﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibKetoan;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmKetchuyen.
	/// </summary>
	public class frmKetchuyen : System.Windows.Forms.Form
	{
		#region khai bao bien su dung trong ham
		private DataSet ds=new DataSet();
		private string sql="";		
		private AccessData a;
		private string s_mmyy;
		private string s_yy;	
		private string s_yyyy;
		private int l_id;
		private int i_userId;
		private string s_mm;

		private bool b_khoanmuc1=true,b_khoanmuc2=true,b_khoanmuc3=true,b_khoanmuc4=true;
		private bool b_khoanmucdich1=true,b_khoanmucdich2=true,b_khoanmucdich3=true,b_khoanmucdich4=true;

		private DataTable dtkhoanmuc1=new DataTable();
		private DataTable dtkhoanmuc2=new DataTable();
		private DataTable dtkhoanmuc3=new DataTable();
		private DataTable dtkhoanmuc4=new DataTable();
		private DataTable dtkhoanmucdich1=new DataTable();
		private DataTable dtkhoanmucdich2=new DataTable();
		private DataTable dtkhoanmucdich3=new DataTable();
		private DataTable dtkhoanmucdich4=new DataTable();
		
		private Brush disabledTextBrush;
		private Brush currentRowBackBrush;
		private Font currentRowFont;
		private DataTable dtkc=new DataTable();
		private DataTable dt=new DataTable();
		private DataTable dttk=new DataTable();
		private DataTable dtlk=new DataTable();
		private DataTable dtnv=new DataTable();
		private DataGridTableStyle ts;
		private int checkCol=0;
		private bool afterCurrentCellChanged;
		#endregion ket thuc khai bao bien su dung trong ham

		#region khai bao control
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ComboBox cbono_co;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.CheckBox chkKetchuyen;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.Label label17;
		private System.Windows.Forms.TextBox txtNhomkmcpn;
		private System.Windows.Forms.TextBox txtSobtoan;
		private System.Windows.Forms.TextBox txtTutk;
		private System.Windows.Forms.TextBox txtKmcpnguon;
		private System.Windows.Forms.CheckBox chkKmcpn;
		private System.Windows.Forms.TextBox txtSangtk;
		private System.Windows.Forms.TextBox txtTenbtoan;
		private System.Windows.Forms.TextBox txtKmcpdich;
		private System.Windows.Forms.TextBox txtDtthnguon;
		private System.Windows.Forms.CheckBox chkTuDtthn;
		private System.Windows.Forms.TextBox txtDtthdich;
		private System.Windows.Forms.Button butBoqua;
		private System.Windows.Forms.Button butHuy;
		private System.Windows.Forms.Button butLuu;
		private System.Windows.Forms.Button butSua;
		private System.Windows.Forms.Button butMoi;
		private System.Windows.Forms.Label label18;
		private System.Windows.Forms.Button butKetthuc;
		private System.Windows.Forms.Button butXoa;
		private System.Windows.Forms.Button butXem;
		private System.Windows.Forms.DataGrid dataGrid2;
		private System.Windows.Forms.CheckBox chkAll;
		#endregion ket thuc khai bao control
		private System.Windows.Forms.NumericUpDown stt;
		private System.Windows.Forms.ComboBox cboKysl;
		private LibList.List listkmnguon;
		private LibList.List listkmdich;
		private LibList.List listngvunguon;
		private LibList.List listngvudich;
		private LibList.List listtutk;
		private LibList.List listsangtk;
		private System.Windows.Forms.Button butketchuyen;
		private System.Windows.Forms.Button butcoppy;
		private System.Windows.Forms.Button butlaymau;
		private System.Windows.Forms.Label label19;
		private System.Windows.Forms.Label label20;
		private System.Windows.Forms.Label label21;
		private System.Windows.Forms.Label label22;
		private System.Windows.Forms.Label label23;
		private System.Windows.Forms.Label label24;
		private System.Windows.Forms.Label label25;
		private System.Windows.Forms.Label label26;
		private System.Windows.Forms.Label label27;
		private LibList.List listkmcpdich2;
		private LibList.List listKmcpnguon2;
		private System.Windows.Forms.TextBox txtKmcpdich2;
		private System.Windows.Forms.CheckBox chkkmcpnguon2;
		private System.Windows.Forms.TextBox txtKmcpnguon2;
		private LibList.List listKmcpdich4;
		private LibList.List listKmcpnguon4;
		private System.Windows.Forms.TextBox txtKmcpdich4;
		private System.Windows.Forms.CheckBox chkKmcpnguon4;
		private System.Windows.Forms.TextBox txtKmcpnguon4;
		private LibList.List listKmcpdich3;
		private LibList.List listKmcpnguon3;
		private System.Windows.Forms.TextBox txtKmcpdich3;
		private System.Windows.Forms.CheckBox chkKmcpnguon3;
		private System.Windows.Forms.TextBox txtKmcpnguon3;
		private LibList.List listlkdich;
		private LibList.List listlknguon;
		private System.Windows.Forms.TextBox txtLKdich;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.CheckBox chkTulkn;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.TextBox txtLKnguon;
		private System.Windows.Forms.Label label11;
		
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmKetchuyen(AccessData acc,string mmyy,int i_userid,string yyyy)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			a=acc;
			s_mmyy=mmyy;
			i_userId=i_userid;
			s_mm=mmyy.Substring(0,2).Trim().ToString();
			s_yy=mmyy.Substring(2,2).Trim().ToString();	
			s_yyyy=yyyy;			
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmKetchuyen));
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.txtNhomkmcpn = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.cbono_co = new System.Windows.Forms.ComboBox();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.chkKetchuyen = new System.Windows.Forms.CheckBox();
			this.label7 = new System.Windows.Forms.Label();
			this.txtSobtoan = new System.Windows.Forms.TextBox();
			this.txtTutk = new System.Windows.Forms.TextBox();
			this.txtKmcpnguon = new System.Windows.Forms.TextBox();
			this.label8 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.chkKmcpn = new System.Windows.Forms.CheckBox();
			this.txtSangtk = new System.Windows.Forms.TextBox();
			this.label10 = new System.Windows.Forms.Label();
			this.txtTenbtoan = new System.Windows.Forms.TextBox();
			this.label12 = new System.Windows.Forms.Label();
			this.txtKmcpdich = new System.Windows.Forms.TextBox();
			this.label13 = new System.Windows.Forms.Label();
			this.txtDtthnguon = new System.Windows.Forms.TextBox();
			this.label16 = new System.Windows.Forms.Label();
			this.chkTuDtthn = new System.Windows.Forms.CheckBox();
			this.txtDtthdich = new System.Windows.Forms.TextBox();
			this.label17 = new System.Windows.Forms.Label();
			this.butcoppy = new System.Windows.Forms.Button();
			this.butlaymau = new System.Windows.Forms.Button();
			this.butBoqua = new System.Windows.Forms.Button();
			this.butHuy = new System.Windows.Forms.Button();
			this.butLuu = new System.Windows.Forms.Button();
			this.butSua = new System.Windows.Forms.Button();
			this.butMoi = new System.Windows.Forms.Button();
			this.label18 = new System.Windows.Forms.Label();
			this.butketchuyen = new System.Windows.Forms.Button();
			this.cboKysl = new System.Windows.Forms.ComboBox();
			this.butKetthuc = new System.Windows.Forms.Button();
			this.butXoa = new System.Windows.Forms.Button();
			this.butXem = new System.Windows.Forms.Button();
			this.dataGrid2 = new System.Windows.Forms.DataGrid();
			this.chkAll = new System.Windows.Forms.CheckBox();
			this.stt = new System.Windows.Forms.NumericUpDown();
			this.listtutk = new LibList.List();
			this.listsangtk = new LibList.List();
			this.listkmnguon = new LibList.List();
			this.listkmdich = new LibList.List();
			this.listngvunguon = new LibList.List();
			this.listngvudich = new LibList.List();
			this.listkmcpdich2 = new LibList.List();
			this.listKmcpnguon2 = new LibList.List();
			this.txtKmcpdich2 = new System.Windows.Forms.TextBox();
			this.label19 = new System.Windows.Forms.Label();
			this.chkkmcpnguon2 = new System.Windows.Forms.CheckBox();
			this.label20 = new System.Windows.Forms.Label();
			this.txtKmcpnguon2 = new System.Windows.Forms.TextBox();
			this.label21 = new System.Windows.Forms.Label();
			this.listKmcpdich4 = new LibList.List();
			this.listKmcpnguon4 = new LibList.List();
			this.txtKmcpdich4 = new System.Windows.Forms.TextBox();
			this.label22 = new System.Windows.Forms.Label();
			this.chkKmcpnguon4 = new System.Windows.Forms.CheckBox();
			this.label23 = new System.Windows.Forms.Label();
			this.txtKmcpnguon4 = new System.Windows.Forms.TextBox();
			this.label24 = new System.Windows.Forms.Label();
			this.listKmcpdich3 = new LibList.List();
			this.listKmcpnguon3 = new LibList.List();
			this.txtKmcpdich3 = new System.Windows.Forms.TextBox();
			this.label25 = new System.Windows.Forms.Label();
			this.chkKmcpnguon3 = new System.Windows.Forms.CheckBox();
			this.label26 = new System.Windows.Forms.Label();
			this.txtKmcpnguon3 = new System.Windows.Forms.TextBox();
			this.label27 = new System.Windows.Forms.Label();
			this.listlkdich = new LibList.List();
			this.listlknguon = new LibList.List();
			this.txtLKdich = new System.Windows.Forms.TextBox();
			this.label15 = new System.Windows.Forms.Label();
			this.chkTulkn = new System.Windows.Forms.CheckBox();
			this.label14 = new System.Windows.Forms.Label();
			this.txtLKnguon = new System.Windows.Forms.TextBox();
			this.label11 = new System.Windows.Forms.Label();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.stt)).BeginInit();
			this.SuspendLayout();
			// 
			// dataGrid1
			// 
			this.dataGrid1.AlternatingBackColor = System.Drawing.Color.Lavender;
			this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.dataGrid1.BackColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Control;
			this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.Control;
			this.dataGrid1.CaptionFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid1.CaptionForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.DataMember = "";
			this.dataGrid1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid1.ForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.GridLineColor = System.Drawing.Color.Gainsboro;
			this.dataGrid1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
			this.dataGrid1.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
			this.dataGrid1.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.LinkColor = System.Drawing.Color.Teal;
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
			this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.PreferredColumnWidth = 20;
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.RowHeaderWidth = 10;
			this.dataGrid1.SelectionBackColor = System.Drawing.Color.CadetBlue;
			this.dataGrid1.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.Size = new System.Drawing.Size(792, 192);
			this.dataGrid1.TabIndex = 91;
			this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(0, 192);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(40, 16);
			this.label1.TabIndex = 92;
			this.label1.Text = "STT: ";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(0, 216);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(40, 16);
			this.label2.TabIndex = 93;
			this.label2.Text = "Nợ/Có:";
			// 
			// txtNhomkmcpn
			// 
			this.txtNhomkmcpn.Location = new System.Drawing.Point(80, 240);
			this.txtNhomkmcpn.Name = "txtNhomkmcpn";
			this.txtNhomkmcpn.Size = new System.Drawing.Size(80, 20);
			this.txtNhomkmcpn.TabIndex = 9;
			this.txtNhomkmcpn.Text = "";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(0, 240);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(74, 24);
			this.label3.TabIndex = 96;
			this.label3.Text = "Nhóm kmcpn:";
			// 
			// cbono_co
			// 
			this.cbono_co.Items.AddRange(new object[] {
														  "Nợ",
														  "Có",
														  "Nợ - Có"});
			this.cbono_co.Location = new System.Drawing.Point(40, 216);
			this.cbono_co.Name = "cbono_co";
			this.cbono_co.Size = new System.Drawing.Size(80, 21);
			this.cbono_co.TabIndex = 4;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(112, 192);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(64, 16);
			this.label4.TabIndex = 1;
			this.label4.Text = "Kết chuyển:";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(120, 216);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(40, 16);
			this.label5.TabIndex = 99;
			this.label5.Text = "Từ TK:";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(160, 240);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(80, 16);
			this.label6.TabIndex = 100;
			this.label6.Text = "Kmcp nguồn 1:";
			// 
			// chkKetchuyen
			// 
			this.chkKetchuyen.Location = new System.Drawing.Point(176, 192);
			this.chkKetchuyen.Name = "chkKetchuyen";
			this.chkKetchuyen.Size = new System.Drawing.Size(16, 16);
			this.chkKetchuyen.TabIndex = 1;
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(200, 192);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(56, 16);
			this.label7.TabIndex = 102;
			this.label7.Text = "Sổ btoán:";
			// 
			// txtSobtoan
			// 
			this.txtSobtoan.Location = new System.Drawing.Point(262, 192);
			this.txtSobtoan.Name = "txtSobtoan";
			this.txtSobtoan.Size = new System.Drawing.Size(128, 20);
			this.txtSobtoan.TabIndex = 2;
			this.txtSobtoan.Text = "";
			// 
			// txtTutk
			// 
			this.txtTutk.Location = new System.Drawing.Point(160, 216);
			this.txtTutk.Name = "txtTutk";
			this.txtTutk.Size = new System.Drawing.Size(80, 20);
			this.txtTutk.TabIndex = 5;
			this.txtTutk.Text = "";
			this.txtTutk.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtTutk_KeyDown);
			this.txtTutk.Validated += new System.EventHandler(this.txtTutk_Validated);
			this.txtTutk.TextChanged += new System.EventHandler(this.txtTutk_TextChanged);
			// 
			// txtKmcpnguon
			// 
			this.txtKmcpnguon.Location = new System.Drawing.Point(238, 240);
			this.txtKmcpnguon.Name = "txtKmcpnguon";
			this.txtKmcpnguon.Size = new System.Drawing.Size(152, 20);
			this.txtKmcpnguon.TabIndex = 10;
			this.txtKmcpnguon.Text = "";
			this.txtKmcpnguon.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpnguon_KeyDown);
			this.txtKmcpnguon.Validated += new System.EventHandler(this.txtKmcpnguon_Validated);
			this.txtKmcpnguon.TextChanged += new System.EventHandler(this.txtKmcpnguon_TextChanged);
			this.txtKmcpnguon.Enter += new System.EventHandler(this.txtKmcpnguon_Enter);
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(240, 216);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(64, 16);
			this.label8.TabIndex = 106;
			this.label8.Text = "Sang TK:";
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(392, 240);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(72, 16);
			this.label9.TabIndex = 107;
			this.label9.Text = "Từ kmcpn 1:";
			// 
			// chkKmcpn
			// 
			this.chkKmcpn.Location = new System.Drawing.Point(472, 240);
			this.chkKmcpn.Name = "chkKmcpn";
			this.chkKmcpn.Size = new System.Drawing.Size(16, 16);
			this.chkKmcpn.TabIndex = 12;
			// 
			// txtSangtk
			// 
			this.txtSangtk.Location = new System.Drawing.Point(294, 216);
			this.txtSangtk.Name = "txtSangtk";
			this.txtSangtk.Size = new System.Drawing.Size(96, 20);
			this.txtSangtk.TabIndex = 6;
			this.txtSangtk.Text = "";
			this.txtSangtk.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtSangtk_KeyDown);
			this.txtSangtk.Validated += new System.EventHandler(this.txtSangtk_Validated);
			this.txtSangtk.TextChanged += new System.EventHandler(this.txtSangtk_TextChanged);
			// 
			// label10
			// 
			this.label10.Location = new System.Drawing.Point(392, 192);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(64, 16);
			this.label10.TabIndex = 110;
			this.label10.Text = "Tên btoán:";
			// 
			// txtTenbtoan
			// 
			this.txtTenbtoan.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtTenbtoan.Location = new System.Drawing.Point(472, 192);
			this.txtTenbtoan.Name = "txtTenbtoan";
			this.txtTenbtoan.Size = new System.Drawing.Size(312, 20);
			this.txtTenbtoan.TabIndex = 3;
			this.txtTenbtoan.Text = "";
			// 
			// label12
			// 
			this.label12.Location = new System.Drawing.Point(488, 240);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(72, 16);
			this.label12.TabIndex = 113;
			this.label12.Text = "Kmcp đích 1:";
			// 
			// txtKmcpdich
			// 
			this.txtKmcpdich.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtKmcpdich.Location = new System.Drawing.Point(560, 240);
			this.txtKmcpdich.Name = "txtKmcpdich";
			this.txtKmcpdich.Size = new System.Drawing.Size(224, 20);
			this.txtKmcpdich.TabIndex = 11;
			this.txtKmcpdich.Text = "";
			this.txtKmcpdich.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpdich_KeyDown);
			this.txtKmcpdich.Validated += new System.EventHandler(this.txtKmcpdich_Validated);
			this.txtKmcpdich.TextChanged += new System.EventHandler(this.txtKmcpdich_TextChanged);
			this.txtKmcpdich.Enter += new System.EventHandler(this.txtKmcpdich_Enter);
			// 
			// label13
			// 
			this.label13.Location = new System.Drawing.Point(392, 288);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(64, 16);
			this.label13.TabIndex = 116;
			this.label13.Text = "Đtth nguồn:";
			// 
			// txtDtthnguon
			// 
			this.txtDtthnguon.Location = new System.Drawing.Point(472, 288);
			this.txtDtthnguon.Name = "txtDtthnguon";
			this.txtDtthnguon.Size = new System.Drawing.Size(72, 20);
			this.txtDtthnguon.TabIndex = 17;
			this.txtDtthnguon.Text = "";
			this.txtDtthnguon.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtDtthnguon_KeyDown);
			this.txtDtthnguon.Validated += new System.EventHandler(this.txtDtthnguon_Validated);
			this.txtDtthnguon.TextChanged += new System.EventHandler(this.txtDtthnguon_TextChanged);
			// 
			// label16
			// 
			this.label16.Location = new System.Drawing.Point(560, 288);
			this.label16.Name = "label16";
			this.label16.Size = new System.Drawing.Size(56, 16);
			this.label16.TabIndex = 122;
			this.label16.Text = "Từ đtthn:";
			// 
			// chkTuDtthn
			// 
			this.chkTuDtthn.Location = new System.Drawing.Point(608, 288);
			this.chkTuDtthn.Name = "chkTuDtthn";
			this.chkTuDtthn.Size = new System.Drawing.Size(16, 16);
			this.chkTuDtthn.TabIndex = 15;
			// 
			// txtDtthdich
			// 
			this.txtDtthdich.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtDtthdich.Location = new System.Drawing.Point(688, 288);
			this.txtDtthdich.Name = "txtDtthdich";
			this.txtDtthdich.Size = new System.Drawing.Size(96, 20);
			this.txtDtthdich.TabIndex = 18;
			this.txtDtthdich.Text = "";
			this.txtDtthdich.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtDtthdich_KeyDown);
			this.txtDtthdich.Validated += new System.EventHandler(this.txtDtthdich_Validated);
			this.txtDtthdich.TextChanged += new System.EventHandler(this.txtDtthdich_TextChanged);
			// 
			// label17
			// 
			this.label17.Location = new System.Drawing.Point(640, 288);
			this.label17.Name = "label17";
			this.label17.Size = new System.Drawing.Size(56, 16);
			this.label17.TabIndex = 124;
			this.label17.Text = "Đtth đích:";
			// 
			// butcoppy
			// 
			this.butcoppy.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butcoppy.Image = ((System.Drawing.Bitmap)(resources.GetObject("butcoppy.Image")));
			this.butcoppy.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butcoppy.Location = new System.Drawing.Point(384, 312);
			this.butcoppy.Name = "butcoppy";
			this.butcoppy.Size = new System.Drawing.Size(80, 25);
			this.butcoppy.TabIndex = 21;
			this.butcoppy.Text = "&Sao chép";
			this.butcoppy.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// butlaymau
			// 
			this.butlaymau.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butlaymau.Image = ((System.Drawing.Bitmap)(resources.GetObject("butlaymau.Image")));
			this.butlaymau.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butlaymau.Location = new System.Drawing.Point(296, 312);
			this.butlaymau.Name = "butlaymau";
			this.butlaymau.Size = new System.Drawing.Size(88, 25);
			this.butlaymau.TabIndex = 20;
			this.butlaymau.Text = " &Lấy từ mẫu";
			this.butlaymau.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// butBoqua
			// 
			this.butBoqua.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butBoqua.Enabled = false;
			this.butBoqua.Image = ((System.Drawing.Bitmap)(resources.GetObject("butBoqua.Image")));
			this.butBoqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butBoqua.Location = new System.Drawing.Point(704, 312);
			this.butBoqua.Name = "butBoqua";
			this.butBoqua.Size = new System.Drawing.Size(60, 25);
			this.butBoqua.TabIndex = 26;
			this.butBoqua.Text = "&Bỏ qua";
			this.butBoqua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butBoqua.Click += new System.EventHandler(this.butBoqua_Click);
			// 
			// butHuy
			// 
			this.butHuy.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butHuy.Image = ((System.Drawing.Bitmap)(resources.GetObject("butHuy.Image")));
			this.butHuy.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butHuy.Location = new System.Drawing.Point(644, 312);
			this.butHuy.Name = "butHuy";
			this.butHuy.Size = new System.Drawing.Size(60, 25);
			this.butHuy.TabIndex = 25;
			this.butHuy.Text = "     &Hủy";
			this.butHuy.Click += new System.EventHandler(this.butHuy_Click);
			// 
			// butLuu
			// 
			this.butLuu.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butLuu.Enabled = false;
			this.butLuu.Image = ((System.Drawing.Bitmap)(resources.GetObject("butLuu.Image")));
			this.butLuu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butLuu.Location = new System.Drawing.Point(584, 312);
			this.butLuu.Name = "butLuu";
			this.butLuu.Size = new System.Drawing.Size(60, 25);
			this.butLuu.TabIndex = 24;
			this.butLuu.Text = "     &Lưu";
			this.butLuu.Click += new System.EventHandler(this.butLuu_Click);
			// 
			// butSua
			// 
			this.butSua.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butSua.Image = ((System.Drawing.Bitmap)(resources.GetObject("butSua.Image")));
			this.butSua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butSua.Location = new System.Drawing.Point(524, 312);
			this.butSua.Name = "butSua";
			this.butSua.Size = new System.Drawing.Size(60, 25);
			this.butSua.TabIndex = 23;
			this.butSua.Text = "     &Sửa";
			this.butSua.Click += new System.EventHandler(this.butSua_Click);
			// 
			// butMoi
			// 
			this.butMoi.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.butMoi.Image = ((System.Drawing.Bitmap)(resources.GetObject("butMoi.Image")));
			this.butMoi.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butMoi.Location = new System.Drawing.Point(464, 312);
			this.butMoi.Name = "butMoi";
			this.butMoi.Size = new System.Drawing.Size(60, 25);
			this.butMoi.TabIndex = 22;
			this.butMoi.Text = "      &Mới";
			this.butMoi.Click += new System.EventHandler(this.butMoi_Click);
			// 
			// label18
			// 
			this.label18.Location = new System.Drawing.Point(0, 312);
			this.label18.Name = "label18";
			this.label18.Size = new System.Drawing.Size(64, 16);
			this.label18.TabIndex = 141;
			this.label18.Text = "Kỳ số liệu:";
			// 
			// butketchuyen
			// 
			this.butketchuyen.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			this.butketchuyen.Image = ((System.Drawing.Bitmap)(resources.GetObject("butketchuyen.Image")));
			this.butketchuyen.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butketchuyen.Location = new System.Drawing.Point(248, 544);
			this.butketchuyen.Name = "butketchuyen";
			this.butketchuyen.Size = new System.Drawing.Size(88, 25);
			this.butketchuyen.TabIndex = 27;
			this.butketchuyen.Text = "&Kết chuyển";
			this.butketchuyen.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butketchuyen.Click += new System.EventHandler(this.butketchuyen_Click);
			// 
			// cboKysl
			// 
			this.cboKysl.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboKysl.Items.AddRange(new object[] {
														 "Nợ",
														 "Có"});
			this.cboKysl.Location = new System.Drawing.Point(80, 312);
			this.cboKysl.Name = "cboKysl";
			this.cboKysl.Size = new System.Drawing.Size(208, 21);
			this.cboKysl.TabIndex = 19;
			this.cboKysl.SelectedIndexChanged += new System.EventHandler(this.cboKysl_SelectedIndexChanged);
			// 
			// butKetthuc
			// 
			this.butKetthuc.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			this.butKetthuc.Image = ((System.Drawing.Bitmap)(resources.GetObject("butKetthuc.Image")));
			this.butKetthuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butKetthuc.Location = new System.Drawing.Point(464, 544);
			this.butKetthuc.Name = "butKetthuc";
			this.butKetthuc.Size = new System.Drawing.Size(70, 25);
			this.butKetthuc.TabIndex = 30;
			this.butKetthuc.Text = "&Kết thúc";
			this.butKetthuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butKetthuc.Click += new System.EventHandler(this.butKetthuc_Click);
			// 
			// butXoa
			// 
			this.butXoa.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			this.butXoa.Enabled = false;
			this.butXoa.Image = ((System.Drawing.Bitmap)(resources.GetObject("butXoa.Image")));
			this.butXoa.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butXoa.Location = new System.Drawing.Point(404, 544);
			this.butXoa.Name = "butXoa";
			this.butXoa.Size = new System.Drawing.Size(60, 25);
			this.butXoa.TabIndex = 29;
			this.butXoa.Text = "     &Xóa";
			// 
			// butXem
			// 
			this.butXem.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			this.butXem.BackColor = System.Drawing.SystemColors.Control;
			this.butXem.ForeColor = System.Drawing.SystemColors.WindowText;
			this.butXem.Image = ((System.Drawing.Bitmap)(resources.GetObject("butXem.Image")));
			this.butXem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butXem.Location = new System.Drawing.Point(336, 544);
			this.butXem.Name = "butXem";
			this.butXem.Size = new System.Drawing.Size(68, 25);
			this.butXem.TabIndex = 28;
			this.butXem.Text = "     &Xem";
			// 
			// dataGrid2
			// 
			this.dataGrid2.AlternatingBackColor = System.Drawing.Color.Lavender;
			this.dataGrid2.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.dataGrid2.BackColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid2.BackgroundColor = System.Drawing.SystemColors.Control;
			this.dataGrid2.CaptionBackColor = System.Drawing.SystemColors.Control;
			this.dataGrid2.CaptionFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid2.CaptionForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid2.DataMember = "";
			this.dataGrid2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid2.ForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid2.GridLineColor = System.Drawing.Color.Gainsboro;
			this.dataGrid2.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
			this.dataGrid2.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
			this.dataGrid2.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid2.LinkColor = System.Drawing.Color.Teal;
			this.dataGrid2.Location = new System.Drawing.Point(0, 344);
			this.dataGrid2.Name = "dataGrid2";
			this.dataGrid2.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
			this.dataGrid2.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid2.ReadOnly = true;
			this.dataGrid2.RowHeaderWidth = 10;
			this.dataGrid2.SelectionBackColor = System.Drawing.Color.CadetBlue;
			this.dataGrid2.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid2.Size = new System.Drawing.Size(792, 200);
			this.dataGrid2.TabIndex = 140;
			// 
			// chkAll
			// 
			this.chkAll.Appearance = System.Windows.Forms.Appearance.Button;
			this.chkAll.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.chkAll.Location = new System.Drawing.Point(40, -2);
			this.chkAll.Name = "chkAll";
			this.chkAll.Size = new System.Drawing.Size(23, 21);
			this.chkAll.TabIndex = 149;
			this.chkAll.Text = "...";
			this.chkAll.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.chkAll.CheckedChanged += new System.EventHandler(this.chkAll_CheckedChanged);
			// 
			// stt
			// 
			this.stt.Enabled = false;
			this.stt.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.stt.Location = new System.Drawing.Point(40, 192);
			this.stt.Name = "stt";
			this.stt.Size = new System.Drawing.Size(61, 21);
			this.stt.TabIndex = 0;
			// 
			// listtutk
			// 
			this.listtutk.BackColor = System.Drawing.SystemColors.Info;
			this.listtutk.ColumnCount = 0;
			this.listtutk.Location = new System.Drawing.Point(176, 216);
			this.listtutk.MatchBufferTimeOut = 1000;
			this.listtutk.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listtutk.Name = "listtutk";
			this.listtutk.Size = new System.Drawing.Size(32, 17);
			this.listtutk.TabIndex = 151;
			this.listtutk.TextIndex = -1;
			this.listtutk.TextMember = null;
			this.listtutk.ValueIndex = -1;
			this.listtutk.Visible = false;
			// 
			// listsangtk
			// 
			this.listsangtk.BackColor = System.Drawing.SystemColors.Info;
			this.listsangtk.ColumnCount = 0;
			this.listsangtk.Location = new System.Drawing.Point(344, 216);
			this.listsangtk.MatchBufferTimeOut = 1000;
			this.listsangtk.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listsangtk.Name = "listsangtk";
			this.listsangtk.Size = new System.Drawing.Size(32, 17);
			this.listsangtk.TabIndex = 152;
			this.listsangtk.TextIndex = -1;
			this.listsangtk.TextMember = null;
			this.listsangtk.ValueIndex = -1;
			this.listsangtk.Visible = false;
			// 
			// listkmnguon
			// 
			this.listkmnguon.BackColor = System.Drawing.SystemColors.Info;
			this.listkmnguon.ColumnCount = 0;
			this.listkmnguon.Location = new System.Drawing.Point(296, 240);
			this.listkmnguon.MatchBufferTimeOut = 1000;
			this.listkmnguon.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listkmnguon.Name = "listkmnguon";
			this.listkmnguon.Size = new System.Drawing.Size(32, 17);
			this.listkmnguon.TabIndex = 155;
			this.listkmnguon.TextIndex = -1;
			this.listkmnguon.TextMember = null;
			this.listkmnguon.ValueIndex = -1;
			this.listkmnguon.Visible = false;
			// 
			// listkmdich
			// 
			this.listkmdich.BackColor = System.Drawing.SystemColors.Info;
			this.listkmdich.ColumnCount = 0;
			this.listkmdich.Location = new System.Drawing.Point(640, 240);
			this.listkmdich.MatchBufferTimeOut = 1000;
			this.listkmdich.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listkmdich.Name = "listkmdich";
			this.listkmdich.Size = new System.Drawing.Size(32, 17);
			this.listkmdich.TabIndex = 156;
			this.listkmdich.TextIndex = -1;
			this.listkmdich.TextMember = null;
			this.listkmdich.ValueIndex = -1;
			this.listkmdich.Visible = false;
			// 
			// listngvunguon
			// 
			this.listngvunguon.BackColor = System.Drawing.SystemColors.Info;
			this.listngvunguon.ColumnCount = 0;
			this.listngvunguon.Location = new System.Drawing.Point(488, 288);
			this.listngvunguon.MatchBufferTimeOut = 1000;
			this.listngvunguon.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listngvunguon.Name = "listngvunguon";
			this.listngvunguon.Size = new System.Drawing.Size(32, 17);
			this.listngvunguon.TabIndex = 157;
			this.listngvunguon.TextIndex = -1;
			this.listngvunguon.TextMember = null;
			this.listngvunguon.ValueIndex = -1;
			this.listngvunguon.Visible = false;
			// 
			// listngvudich
			// 
			this.listngvudich.BackColor = System.Drawing.SystemColors.Info;
			this.listngvudich.ColumnCount = 0;
			this.listngvudich.Location = new System.Drawing.Point(712, 288);
			this.listngvudich.MatchBufferTimeOut = 1000;
			this.listngvudich.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listngvudich.Name = "listngvudich";
			this.listngvudich.Size = new System.Drawing.Size(32, 17);
			this.listngvudich.TabIndex = 158;
			this.listngvudich.TextIndex = -1;
			this.listngvudich.TextMember = null;
			this.listngvudich.ValueIndex = -1;
			this.listngvudich.Visible = false;
			// 
			// listkmcpdich2
			// 
			this.listkmcpdich2.BackColor = System.Drawing.SystemColors.Info;
			this.listkmcpdich2.ColumnCount = 0;
			this.listkmcpdich2.Location = new System.Drawing.Point(328, 264);
			this.listkmcpdich2.MatchBufferTimeOut = 1000;
			this.listkmcpdich2.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listkmcpdich2.Name = "listkmcpdich2";
			this.listkmcpdich2.Size = new System.Drawing.Size(32, 17);
			this.listkmcpdich2.TabIndex = 166;
			this.listkmcpdich2.TextIndex = -1;
			this.listkmcpdich2.TextMember = null;
			this.listkmcpdich2.ValueIndex = -1;
			this.listkmcpdich2.Visible = false;
			// 
			// listKmcpnguon2
			// 
			this.listKmcpnguon2.BackColor = System.Drawing.SystemColors.Info;
			this.listKmcpnguon2.ColumnCount = 0;
			this.listKmcpnguon2.Location = new System.Drawing.Point(88, 264);
			this.listKmcpnguon2.MatchBufferTimeOut = 1000;
			this.listKmcpnguon2.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listKmcpnguon2.Name = "listKmcpnguon2";
			this.listKmcpnguon2.Size = new System.Drawing.Size(32, 17);
			this.listKmcpnguon2.TabIndex = 165;
			this.listKmcpnguon2.TextIndex = -1;
			this.listKmcpnguon2.TextMember = null;
			this.listKmcpnguon2.ValueIndex = -1;
			this.listKmcpnguon2.Visible = false;
			// 
			// txtKmcpdich2
			// 
			this.txtKmcpdich2.Location = new System.Drawing.Point(310, 264);
			this.txtKmcpdich2.Name = "txtKmcpdich2";
			this.txtKmcpdich2.Size = new System.Drawing.Size(80, 20);
			this.txtKmcpdich2.TabIndex = 13;
			this.txtKmcpdich2.Text = "";
			this.txtKmcpdich2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpdich2_KeyDown);
			this.txtKmcpdich2.Validated += new System.EventHandler(this.txtKmcpdich2_Validated);
			this.txtKmcpdich2.TextChanged += new System.EventHandler(this.txtKmcpdich2_TextChanged);
			this.txtKmcpdich2.Enter += new System.EventHandler(this.txtKmcpdich2_Enter);
			// 
			// label19
			// 
			this.label19.Location = new System.Drawing.Point(240, 264);
			this.label19.Name = "label19";
			this.label19.Size = new System.Drawing.Size(72, 16);
			this.label19.TabIndex = 164;
			this.label19.Text = "Kmcp đích 2:";
			// 
			// chkkmcpnguon2
			// 
			this.chkkmcpnguon2.Location = new System.Drawing.Point(224, 264);
			this.chkkmcpnguon2.Name = "chkkmcpnguon2";
			this.chkkmcpnguon2.Size = new System.Drawing.Size(16, 16);
			this.chkkmcpnguon2.TabIndex = 160;
			// 
			// label20
			// 
			this.label20.Location = new System.Drawing.Point(160, 264);
			this.label20.Name = "label20";
			this.label20.Size = new System.Drawing.Size(72, 16);
			this.label20.TabIndex = 163;
			this.label20.Text = "Từ kmcpn 2:";
			// 
			// txtKmcpnguon2
			// 
			this.txtKmcpnguon2.Location = new System.Drawing.Point(80, 264);
			this.txtKmcpnguon2.Name = "txtKmcpnguon2";
			this.txtKmcpnguon2.Size = new System.Drawing.Size(80, 20);
			this.txtKmcpnguon2.TabIndex = 12;
			this.txtKmcpnguon2.Text = "";
			this.txtKmcpnguon2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpnguon2_KeyDown);
			this.txtKmcpnguon2.Validated += new System.EventHandler(this.txtKmcpnguon2_Validated);
			this.txtKmcpnguon2.TextChanged += new System.EventHandler(this.txtKmcpnguon2_TextChanged);
			this.txtKmcpnguon2.Enter += new System.EventHandler(this.txtKmcpnguon2_Enter);
			// 
			// label21
			// 
			this.label21.Location = new System.Drawing.Point(0, 264);
			this.label21.Name = "label21";
			this.label21.Size = new System.Drawing.Size(80, 16);
			this.label21.TabIndex = 162;
			this.label21.Text = "Kmcp nguồn 2:";
			// 
			// listKmcpdich4
			// 
			this.listKmcpdich4.BackColor = System.Drawing.SystemColors.Info;
			this.listKmcpdich4.ColumnCount = 0;
			this.listKmcpdich4.Location = new System.Drawing.Point(328, 288);
			this.listKmcpdich4.MatchBufferTimeOut = 1000;
			this.listKmcpdich4.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listKmcpdich4.Name = "listKmcpdich4";
			this.listKmcpdich4.Size = new System.Drawing.Size(32, 17);
			this.listKmcpdich4.TabIndex = 182;
			this.listKmcpdich4.TextIndex = -1;
			this.listKmcpdich4.TextMember = null;
			this.listKmcpdich4.ValueIndex = -1;
			this.listKmcpdich4.Visible = false;
			// 
			// listKmcpnguon4
			// 
			this.listKmcpnguon4.BackColor = System.Drawing.SystemColors.Info;
			this.listKmcpnguon4.ColumnCount = 0;
			this.listKmcpnguon4.Location = new System.Drawing.Point(96, 288);
			this.listKmcpnguon4.MatchBufferTimeOut = 1000;
			this.listKmcpnguon4.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listKmcpnguon4.Name = "listKmcpnguon4";
			this.listKmcpnguon4.Size = new System.Drawing.Size(32, 17);
			this.listKmcpnguon4.TabIndex = 181;
			this.listKmcpnguon4.TextIndex = -1;
			this.listKmcpnguon4.TextMember = null;
			this.listKmcpnguon4.ValueIndex = -1;
			this.listKmcpnguon4.Visible = false;
			// 
			// txtKmcpdich4
			// 
			this.txtKmcpdich4.Location = new System.Drawing.Point(310, 288);
			this.txtKmcpdich4.Name = "txtKmcpdich4";
			this.txtKmcpdich4.Size = new System.Drawing.Size(80, 20);
			this.txtKmcpdich4.TabIndex = 16;
			this.txtKmcpdich4.Text = "";
			this.txtKmcpdich4.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpdich4_KeyDown);
			this.txtKmcpdich4.Validated += new System.EventHandler(this.txtKmcpdich4_Validated);
			this.txtKmcpdich4.TextChanged += new System.EventHandler(this.txtKmcpdich4_TextChanged);
			this.txtKmcpdich4.Enter += new System.EventHandler(this.txtKmcpdich4_Enter);
			// 
			// label22
			// 
			this.label22.Location = new System.Drawing.Point(240, 288);
			this.label22.Name = "label22";
			this.label22.Size = new System.Drawing.Size(72, 16);
			this.label22.TabIndex = 180;
			this.label22.Text = "Kmcp đích 4:";
			// 
			// chkKmcpnguon4
			// 
			this.chkKmcpnguon4.Location = new System.Drawing.Point(224, 288);
			this.chkKmcpnguon4.Name = "chkKmcpnguon4";
			this.chkKmcpnguon4.Size = new System.Drawing.Size(16, 16);
			this.chkKmcpnguon4.TabIndex = 176;
			// 
			// label23
			// 
			this.label23.Location = new System.Drawing.Point(160, 288);
			this.label23.Name = "label23";
			this.label23.Size = new System.Drawing.Size(72, 16);
			this.label23.TabIndex = 179;
			this.label23.Text = "Từ kmcpn 4:";
			// 
			// txtKmcpnguon4
			// 
			this.txtKmcpnguon4.Location = new System.Drawing.Point(80, 288);
			this.txtKmcpnguon4.Name = "txtKmcpnguon4";
			this.txtKmcpnguon4.Size = new System.Drawing.Size(80, 20);
			this.txtKmcpnguon4.TabIndex = 15;
			this.txtKmcpnguon4.Text = "";
			this.txtKmcpnguon4.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpnguon4_KeyDown);
			this.txtKmcpnguon4.Validated += new System.EventHandler(this.txtKmcpnguon4_Validated);
			this.txtKmcpnguon4.TextChanged += new System.EventHandler(this.txtKmcpnguon4_TextChanged);
			this.txtKmcpnguon4.Enter += new System.EventHandler(this.txtKmcpnguon4_Enter);
			// 
			// label24
			// 
			this.label24.Location = new System.Drawing.Point(0, 288);
			this.label24.Name = "label24";
			this.label24.Size = new System.Drawing.Size(80, 16);
			this.label24.TabIndex = 178;
			this.label24.Text = "Kmcp nguồn 4:";
			// 
			// listKmcpdich3
			// 
			this.listKmcpdich3.BackColor = System.Drawing.SystemColors.Info;
			this.listKmcpdich3.ColumnCount = 0;
			this.listKmcpdich3.Location = new System.Drawing.Point(712, 264);
			this.listKmcpdich3.MatchBufferTimeOut = 1000;
			this.listKmcpdich3.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listKmcpdich3.Name = "listKmcpdich3";
			this.listKmcpdich3.Size = new System.Drawing.Size(32, 17);
			this.listKmcpdich3.TabIndex = 174;
			this.listKmcpdich3.TextIndex = -1;
			this.listKmcpdich3.TextMember = null;
			this.listKmcpdich3.ValueIndex = -1;
			this.listKmcpdich3.Visible = false;
			// 
			// listKmcpnguon3
			// 
			this.listKmcpnguon3.BackColor = System.Drawing.SystemColors.Info;
			this.listKmcpnguon3.ColumnCount = 0;
			this.listKmcpnguon3.Location = new System.Drawing.Point(504, 264);
			this.listKmcpnguon3.MatchBufferTimeOut = 1000;
			this.listKmcpnguon3.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listKmcpnguon3.Name = "listKmcpnguon3";
			this.listKmcpnguon3.Size = new System.Drawing.Size(32, 17);
			this.listKmcpnguon3.TabIndex = 173;
			this.listKmcpnguon3.TextIndex = -1;
			this.listKmcpnguon3.TextMember = null;
			this.listKmcpnguon3.ValueIndex = -1;
			this.listKmcpnguon3.Visible = false;
			// 
			// txtKmcpdich3
			// 
			this.txtKmcpdich3.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtKmcpdich3.Location = new System.Drawing.Point(688, 264);
			this.txtKmcpdich3.Name = "txtKmcpdich3";
			this.txtKmcpdich3.Size = new System.Drawing.Size(96, 20);
			this.txtKmcpdich3.TabIndex = 14;
			this.txtKmcpdich3.Text = "";
			this.txtKmcpdich3.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmcpdich3_KeyDown);
			this.txtKmcpdich3.Validated += new System.EventHandler(this.txtKmcpdich3_Validated);
			this.txtKmcpdich3.TextChanged += new System.EventHandler(this.txtKmcpdich3_TextChanged);
			this.txtKmcpdich3.Enter += new System.EventHandler(this.txtKmcpdich3_Enter);
			// 
			// label25
			// 
			this.label25.Location = new System.Drawing.Point(624, 264);
			this.label25.Name = "label25";
			this.label25.Size = new System.Drawing.Size(72, 16);
			this.label25.TabIndex = 172;
			this.label25.Text = "Kmcp đích 3:";
			// 
			// chkKmcpnguon3
			// 
			this.chkKmcpnguon3.Location = new System.Drawing.Point(608, 264);
			this.chkKmcpnguon3.Name = "chkKmcpnguon3";
			this.chkKmcpnguon3.Size = new System.Drawing.Size(16, 16);
			this.chkKmcpnguon3.TabIndex = 168;
			// 
			// label26
			// 
			this.label26.Location = new System.Drawing.Point(544, 264);
			this.label26.Name = "label26";
			this.label26.Size = new System.Drawing.Size(72, 16);
			this.label26.TabIndex = 171;
			this.label26.Text = "Từ kmcpn 3:";
			// 
			// txtKmcpnguon3
			// 
			this.txtKmcpnguon3.Location = new System.Drawing.Point(472, 264);
			this.txtKmcpnguon3.Name = "txtKmcpnguon3";
			this.txtKmcpnguon3.Size = new System.Drawing.Size(72, 20);
			this.txtKmcpnguon3.TabIndex = 167;
			this.txtKmcpnguon3.Text = "";
			this.txtKmcpnguon3.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtKmpnguon3_KeyDown);
			this.txtKmcpnguon3.Validated += new System.EventHandler(this.txtKmcpnguon3_Validated);
			this.txtKmcpnguon3.TextChanged += new System.EventHandler(this.txtKmcpnguon3_TextChanged);
			this.txtKmcpnguon3.Enter += new System.EventHandler(this.txtKmcpnguon3_Enter);
			// 
			// label27
			// 
			this.label27.Location = new System.Drawing.Point(392, 264);
			this.label27.Name = "label27";
			this.label27.Size = new System.Drawing.Size(80, 16);
			this.label27.TabIndex = 170;
			this.label27.Text = "Kmcp nguồn 3:";
			// 
			// listlkdich
			// 
			this.listlkdich.BackColor = System.Drawing.SystemColors.Info;
			this.listlkdich.ColumnCount = 0;
			this.listlkdich.Location = new System.Drawing.Point(712, 216);
			this.listlkdich.MatchBufferTimeOut = 1000;
			this.listlkdich.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listlkdich.Name = "listlkdich";
			this.listlkdich.Size = new System.Drawing.Size(32, 17);
			this.listlkdich.TabIndex = 190;
			this.listlkdich.TextIndex = -1;
			this.listlkdich.TextMember = null;
			this.listlkdich.ValueIndex = -1;
			this.listlkdich.Visible = false;
			// 
			// listlknguon
			// 
			this.listlknguon.BackColor = System.Drawing.SystemColors.Info;
			this.listlknguon.ColumnCount = 0;
			this.listlknguon.Location = new System.Drawing.Point(504, 216);
			this.listlknguon.MatchBufferTimeOut = 1000;
			this.listlknguon.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listlknguon.Name = "listlknguon";
			this.listlknguon.Size = new System.Drawing.Size(32, 17);
			this.listlknguon.TabIndex = 189;
			this.listlknguon.TextIndex = -1;
			this.listlknguon.TextMember = null;
			this.listlknguon.ValueIndex = -1;
			this.listlknguon.Visible = false;
			// 
			// txtLKdich
			// 
			this.txtLKdich.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtLKdich.Location = new System.Drawing.Point(688, 216);
			this.txtLKdich.Name = "txtLKdich";
			this.txtLKdich.Size = new System.Drawing.Size(96, 20);
			this.txtLKdich.TabIndex = 8;
			this.txtLKdich.Text = "";
			// 
			// label15
			// 
			this.label15.Location = new System.Drawing.Point(640, 216);
			this.label15.Name = "label15";
			this.label15.Size = new System.Drawing.Size(48, 16);
			this.label15.TabIndex = 188;
			this.label15.Text = "LK đích:";
			// 
			// chkTulkn
			// 
			this.chkTulkn.Location = new System.Drawing.Point(608, 216);
			this.chkTulkn.Name = "chkTulkn";
			this.chkTulkn.Size = new System.Drawing.Size(16, 16);
			this.chkTulkn.TabIndex = 184;
			// 
			// label14
			// 
			this.label14.Location = new System.Drawing.Point(560, 216);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(48, 16);
			this.label14.TabIndex = 187;
			this.label14.Text = "Từ lkn:";
			// 
			// txtLKnguon
			// 
			this.txtLKnguon.Location = new System.Drawing.Point(472, 216);
			this.txtLKnguon.Name = "txtLKnguon";
			this.txtLKnguon.Size = new System.Drawing.Size(88, 20);
			this.txtLKnguon.TabIndex = 7;
			this.txtLKnguon.Text = "";
			// 
			// label11
			// 
			this.label11.Location = new System.Drawing.Point(392, 216);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(56, 16);
			this.label11.TabIndex = 186;
			this.label11.Text = "LK nguồn:";
			// 
			// frmKetchuyen
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(792, 573);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.listlkdich,
																		  this.listlknguon,
																		  this.txtLKdich,
																		  this.label15,
																		  this.chkTulkn,
																		  this.label14,
																		  this.txtLKnguon,
																		  this.label11,
																		  this.listKmcpdich4,
																		  this.listKmcpnguon4,
																		  this.txtKmcpdich4,
																		  this.label22,
																		  this.chkKmcpnguon4,
																		  this.label23,
																		  this.txtKmcpnguon4,
																		  this.label24,
																		  this.listKmcpdich3,
																		  this.listKmcpnguon3,
																		  this.txtKmcpdich3,
																		  this.label25,
																		  this.chkKmcpnguon3,
																		  this.label26,
																		  this.txtKmcpnguon3,
																		  this.label27,
																		  this.listkmcpdich2,
																		  this.listKmcpnguon2,
																		  this.txtKmcpdich2,
																		  this.label19,
																		  this.chkkmcpnguon2,
																		  this.label20,
																		  this.txtKmcpnguon2,
																		  this.label21,
																		  this.listngvudich,
																		  this.listngvunguon,
																		  this.listkmdich,
																		  this.listkmnguon,
																		  this.listsangtk,
																		  this.listtutk,
																		  this.stt,
																		  this.chkAll,
																		  this.butXem,
																		  this.butXoa,
																		  this.butKetthuc,
																		  this.cboKysl,
																		  this.butketchuyen,
																		  this.label18,
																		  this.dataGrid2,
																		  this.butMoi,
																		  this.butSua,
																		  this.butLuu,
																		  this.butHuy,
																		  this.butBoqua,
																		  this.butlaymau,
																		  this.butcoppy,
																		  this.txtDtthdich,
																		  this.label17,
																		  this.chkTuDtthn,
																		  this.label16,
																		  this.txtDtthnguon,
																		  this.label13,
																		  this.txtKmcpdich,
																		  this.label12,
																		  this.txtTenbtoan,
																		  this.label10,
																		  this.txtSangtk,
																		  this.chkKmcpn,
																		  this.label9,
																		  this.label8,
																		  this.txtKmcpnguon,
																		  this.txtTutk,
																		  this.txtSobtoan,
																		  this.label7,
																		  this.chkKetchuyen,
																		  this.label6,
																		  this.label5,
																		  this.label4,
																		  this.cbono_co,
																		  this.label3,
																		  this.txtNhomkmcpn,
																		  this.label2,
																		  this.label1,
																		  this.dataGrid1});
			this.Name = "frmKetchuyen";
			this.Text = "Kết chuyển cuối kỳ";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.Load += new System.EventHandler(this.frmKetchuyen_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.stt)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void butKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}		
		private void frmKetchuyen_Load(object sender, System.EventArgs e)
		{				
			ena_object(false);

			
			listtutk.DisplayMember="STK";
			listtutk.TextMember="STK";
			listtutk.ValueMember="STK";

			listsangtk.DisplayMember="STK";
			listsangtk.TextMember="STK";
			listsangtk.ValueMember="STK";

			dttk=a.get_DMTaikhoan("").Tables[0];
			listtutk.DataSource=dttk;			
			listsangtk.DataSource=dttk;
			
			listlknguon.DisplayMember="LK";
			listlknguon.ValueMember="ID";

			listlkdich.DisplayMember="LK";
			listlkdich.ValueMember="ID";

			dtlk=a.get_DMLoaikhoan().Tables[0];
			listlknguon.DataSource=dtlk;			
			listlkdich.DataSource=dtlk;
//
//			listkmnguon.DisplayMember="TEN";
//			listkmnguon.ValueMember="ID";
//
//			listKmcpnguon2.DisplayMember="TEN";
//			listKmcpnguon2.ValueMember="ID";
//
//			listKmcpnguon3.DisplayMember="TEN";
//			listKmcpnguon3.ValueMember="ID";
//
//			listKmcpnguon4.DisplayMember="TEN";
//			listKmcpnguon4.ValueMember="ID";
//
//			listkmdich.DisplayMember="TEN";
//			listkmdich.ValueMember="ID";
//
//			listkmcpdich2.DisplayMember="TEN";
//			listkmcpdich2.ValueMember="ID";
//
//			listKmcpdich3.DisplayMember="TEN";
//			listKmcpdich3.ValueMember="ID";
//
//			listKmcpdich4.DisplayMember="TEN";
//			listKmcpdich4.ValueMember="ID";

			sql="select * from a_nghiepvu where sudung=1";
			sql+=" order by stt";
			dtnv=a.get_data(sql).Tables[0];
			listngvunguon.DisplayMember="TEN";
			listngvunguon.ValueMember="ID";
			listngvunguon.DataSource=dtnv;

			listngvudich.DisplayMember="TEN";
			listngvudich.ValueMember="ID";
			listngvudich.DataSource=dtnv;

			this.currentRowBackBrush = new SolidBrush(Color.FromArgb(0,255, 255));
			this.disabledTextBrush = new SolidBrush(Color.FromArgb(255,0,0));
			this.currentRowFont = new Font(this.dataGrid1.Font.Name, this.dataGrid1.Font.Size, FontStyle.Regular);				

			cboKysl.ValueMember="ID";	
			cboKysl.DisplayMember="TEN";

			cbono_co.SelectedIndex=0;
			load_cboKysl();
			load_grid_ketchuyen(cboKysl.SelectedValue.ToString());
			AddGridTableStyle();
			ref_text();
				

		}
		private void f_LoadKhoanmuc(ref LibList.List listKmuc,ref System.Data.DataTable dt_Dmkmuc,string s_IDLoaikhoanmuc) 		{ 			listKmuc.DisplayMember="TEN"; 			listKmuc.TextMember="MA"; 			listKmuc.ValueMember="TEN";  			dt_Dmkmuc=a.get_DMkhoanmuc(s_IDLoaikhoanmuc)!=null?a.get_DMkhoanmuc(s_IDLoaikhoanmuc).Tables[0]:null; 			listKmuc.DataSource=dt_Dmkmuc; 		}
		private void SetCellFormat(object sender, DataGridFormatCellEventArgs e)
		{
			try
			{
				bool discontinued = (bool) ((e.Column != 0) ? this.dataGrid1[e.Row, 0] : e.CurrentCellValue);
				if(e.Column > 0 && (bool)(this.dataGrid1[e.Row, 0]))//discontinued)
				{
					e.ForeBrush = this.disabledTextBrush;
				}
				else if(e.Column > 0 && e.Row == this.dataGrid1.CurrentRowIndex)
				{
					e.BackBrush = this.currentRowBackBrush;
					e.TextFont = this.currentRowFont;
				}
				if (decimal.Parse(dataGrid1[e.Row,3].ToString())!=0) e.ForeBrush=new SolidBrush(Color.Orange);
			}
			catch{}
		}
		private void RefreshRow(int row)
		{
			Rectangle rect = this.dataGrid1.GetCellBounds(row, 0);
			rect = new Rectangle(rect.Right, rect.Top, this.dataGrid1.Width, rect.Height);
			this.dataGrid1.Invalidate(rect);
		}
		private void BoolValueChanged(object sender, BoolValueChangedEventArgs e)
		{
			this.dataGrid1.EndEdit(this.dataGrid1.TableStyles[0].GridColumnStyles["Discontinued"],e.Row, false);
			RefreshRow(e.Row);
			this.dataGrid1.BeginEdit(this.dataGrid1.TableStyles[0].GridColumnStyles["Discontinued"],e.Row);
		}
		private void AddGridTableStyle()
		{
			DataGridTableStyle ts =new DataGridTableStyle();			
			ts.MappingName = dtkc.TableName;
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.Gainsboro;
			ts.HeaderForeColor = Color.Blue;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			ts.ReadOnly=false;
			ts.RowHeaderWidth=15;	
			ts.PreferredRowHeight=22;
					
			DataGridTextBoxColumn TextCol=new DataGridTextBoxColumn();			
			TextCol.MappingName = "id";
			TextCol.HeaderText = "";
			TextCol.Width = 0;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "stt";
			TextCol.HeaderText = "STT";
			TextCol.Width = 20;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			FormattableBooleanColumn discontinuedCol = new FormattableBooleanColumn();
			discontinuedCol.MappingName = "chon";
			discontinuedCol.HeaderText = "Kết chuyển";
			discontinuedCol.Width = 30;
			discontinuedCol.AllowNull = false;

			discontinuedCol.SetCellFormat += new FormatCellEventHandler(SetCellFormat);
			discontinuedCol.BoolValueChanged += new BoolValueChangedEventHandler(BoolValueChanged);
			ts.GridColumnStyles.Add(discontinuedCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "sobtoan";
			TextCol.HeaderText = "Sổ btoán";
			TextCol.NullText="";
			TextCol.Width = 50;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tenbt";
			TextCol.HeaderText = "tên btoán";
			TextCol.Width = 200;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tinhchat";
			TextCol.HeaderText = "Nợ/Có";
			TextCol.Width = 50;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tentutk";
			TextCol.HeaderText = "Từ tk";
			TextCol.Width = 50;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName ="tensangtk";
			TextCol.HeaderText = "Sang tk";
			TextCol.NullText="";
			TextCol.Width = 50;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "kmcpnguon";
			TextCol.HeaderText = "KMCP nguồn";
			TextCol.Width = 70;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "nhomkmcpn";
			TextCol.HeaderText = "Nhóm KMCP nguồn";
			TextCol.Width = 110;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "dtthnguon";
			TextCol.HeaderText = "DTTH nguồn";
			TextCol.Width = 70;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "lknguon";
			TextCol.HeaderText = "LK nguồn";
			TextCol.Width = 60;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tukmcpn";
			TextCol.HeaderText = "Từ KMCP nguồn";
			TextCol.Width = 90;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "dtthdich";
			TextCol.HeaderText = "DTTH đích";
			TextCol.Width = 60;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "kysl";
			TextCol.HeaderText = "Kỳ số liệu";
			TextCol.Width = 60;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);			

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tulkn";
			TextCol.HeaderText = "Từ LK nguồn";
			TextCol.Width = 70;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "lkdich";
			TextCol.HeaderText = "LK đích";
			TextCol.Width = 50;
			TextCol.NullText="";
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			//			TextCol=new DataGridTextBoxColumn();
			//			TextCol.MappingName = "userid";
			//			TextCol.HeaderText = "iduser";
			//			TextCol.Width = 50;
			//			TextCol.NullText="";
			//			ts.GridColumnStyles.Add(TextCol);
			//			dataGrid1.TableStyles.Add(ts);
			//
			//			TextCol=new DataGridTextBoxColumn();
			//			TextCol.MappingName = "ngayud";
			//			TextCol.HeaderText = "Ngày ứng dụng";
			//			TextCol.Width = 80;
			//			TextCol.NullText="";
			//			ts.GridColumnStyles.Add(TextCol);
			//			dataGrid1.TableStyles.Add(ts);	
	 
		}

		private void hidelist()
		{
			if(!listtutk.Focused) listtutk.Hide();
			if(!listsangtk.Focused) listsangtk.Hide();
			if(!listlknguon.Focused) listlknguon.Hide();
			if(!listlkdich.Focused) listlkdich.Hide();
			if(!listkmnguon.Focused) listkmnguon.Hide();
			if(!listkmdich.Focused) listkmdich.Hide();
			if(!listngvunguon.Focused) listngvunguon.Hide();
			if(!listngvudich.Focused) listngvudich.Hide();
			if(!listKmcpnguon2.Focused) listKmcpnguon2.Hide();
			if(!listKmcpnguon3.Focused) listKmcpnguon3.Hide();
			if(!listKmcpnguon4.Focused) listKmcpnguon4.Hide();
			if(!listkmcpdich2.Focused) listkmcpdich2.Hide();
			if(!listKmcpdich3.Focused) listKmcpdich3.Hide();
			if(!listKmcpdich4.Focused) listKmcpdich4.Hide();
		}
		
		private void Filter_List(LibList.List listDulieu,string s_Dkloc,string s_Tenfield_1,string s_Tenfield_2) 		{ 			try 			{ 				string s_Dieukien=s_Tenfield_1.Trim()+" like '%"+s_Dkloc.Trim()+"%'"; 				if (s_Tenfield_2.Trim()!="") s_Dieukien+=" or "+s_Tenfield_2.Trim()+" like '%"+s_Dkloc.Trim()+"%'"; 				CurrencyManager cm= (CurrencyManager)BindingContext[listDulieu.DataSource]; 				System.Data.DataView dv=(System.Data.DataView)cm.List; 				dv.RowFilter=s_Dieukien; 			} 			catch{} 		}

		private void Filter_stk(string ma,LibList.List list)
		{
			CurrencyManager cm= (CurrencyManager)BindingContext[list.DataSource];
			DataView dv=(DataView)cm.List;
			sql="stk like '"+ma.Trim()+"%' or ttk like '%"+ma.Trim()+"%'";
			dv.RowFilter=sql;
		}			
		private void load_cboKysl()
		{
			cboKysl.DataSource=a.get_data(sql="select id,ten||' Năm "+s_yyyy+"' as ten from "+a.user+".a_dmkybc order by id").Tables[0];
			
		}
		private void load_grid_ketchuyen(string kysl)
		{
			sql="select a.id as id,a.stt as stt,a.ketchuyen as ketchuyen,a.sobtoan as sobtoan,";
			sql+=" a.tenbt as tenbt,a.tinhchat as tinhchat,b.ten as tentc,";
			sql+=" a.tutk as tutk,c.stk as tentutk,a.sangtk as sangtk,d.stk as tensangtk,";
			sql+=" a.kmcpnguon as kmcpnguon,a.nhomkmcpn as nhomkmcpn,a.dtthnguon as dtthnguon,";
			sql+=" a.tukmcpn as tukmcpn,a.kmcpdich as kmcpdich,a.tudtthn as tudtthn,a.dtthdich as dtthdich,";
			sql+=" a.kysl as kysl,a.lknguon as lknguon,a.tulkn as tulkn,a.lkdich as lkdich ";
			sql+=" from "+a.user+".a_ctkc"+s_yy+" a ";
			sql+=" left join "+a.user+".a_dmtctk b on b.id=a.tinhchat";
			sql+=" left join "+a.user+".a_dmtk c on c.id=a.tutk ";
			sql+=" left join "+a.user+".a_dmtk d on d.id=a.sangtk where kysl="+kysl+" order by stt";				
			//
			//sql="select * from "+user+".a_ctkc"+s_yy+" where kysl="+kysl+" order by stt";
			dtkc=a.get_data(sql).Tables[0];
			dtkc.Columns.Add(new DataColumn("chon",typeof(bool)));
			foreach(DataRow r in dtkc.Rows) r["chon"]=r["ketchuyen"].ToString()=="1"?true:false;
			dataGrid1.DataSource=dtkc;
				
		}
		private void ena_object(bool ena)
		{
			stt.Enabled=txtDtthdich.Enabled=txtDtthnguon.Enabled=txtKmcpdich.Enabled=txtKmcpnguon.Enabled=txtLKdich.Enabled=txtLKnguon.Enabled=txtNhomkmcpn.Enabled=txtSangtk.Enabled=txtSobtoan.Enabled=txtTenbtoan.Enabled=txtTutk.Enabled=ena;
			cbono_co.Enabled=chkKetchuyen.Enabled=chkKmcpn.Enabled=chkTuDtthn.Enabled=chkTulkn.Enabled=ena;
			txtKmcpnguon2.Enabled=txtKmcpdich2.Enabled=txtKmcpnguon3.Enabled=txtKmcpdich3.Enabled=txtKmcpnguon4.Enabled=txtKmcpdich4.Enabled=ena;
			butXoa.Enabled=butLuu.Enabled=butBoqua.Enabled=ena;
			chkAll.Enabled=butSua.Enabled=butHuy.Enabled=butKetthuc.Enabled=!ena;			
		}

		private void butMoi_Click(object sender, System.EventArgs e)
		{
			try
			{
				stt.Value=decimal.Parse(a.get_data("select max(stt) from "+a.user+".a_ctkc"+s_yy+"").Tables[0].Rows[0][0].ToString())+1;
			}
			catch{stt.Value=1;}
			l_id=0;			
			ena_object(true);
			stt.Focus();
		}

		private void butBoqua_Click(object sender, System.EventArgs e)
		{
			ref_text();
			ena_object(false);
		}

		private void butSua_Click(object sender, System.EventArgs e)
		{
			if (dtkc.Rows.Count==0) return;
			l_id=int.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString());
			ena_object(true);
			stt.Focus();
		}
		private bool kiemtra()
		{
			if (txtSobtoan.Text=="")
			{
				MessageBox.Show("Yêu cầu nhập số bút toán !",a.Msg);
				txtSobtoan.Focus();
				return false;
			}
			else if (txtTenbtoan.Text=="")
			{
				MessageBox.Show("Yêu cầu nhập tên bút toán !",a.Msg);
				txtTenbtoan.Focus();
				return false;
			}
			else if (txtTutk.Text=="")
			{
				MessageBox.Show("Yêu cầu nhập Tài khoản gốc kết chuyển !",a.Msg);
				txtTutk.Focus();
				return false;
			}
			else if (txtSangtk.Text=="")
			{
				MessageBox.Show("Yêu cầu nhập Tài khoản kết chuyển sang !",a.Msg);
				txtSangtk.Focus();
				return false;
			}
			return true;
		}
		private void butLuu_Click(object sender, System.EventArgs e)
		{
			if (!kiemtra()) return ;
			if (l_id==0)
			{
				try
				{
					l_id=int.Parse(a.get_data("select max(id) from "+a.user+".a_ctkc"+s_yy+"").Tables[0].Rows[0][0].ToString())+1;
				}
				catch{l_id=1;}
			}
			int i_idtutk=0,i_idsangtk=0, i_tinhchattk=0, i_kmcpnguon=0,i_kmcpnguon2=0,i_kmcpnguon3=0,i_kmcpnguon4=0;
			int i_kmcpdich=0,i_kmcpdich2=0,i_kmcpdich3=0,i_kmcpdich4=0,i_lknguon=0,i_lkdich=0,i_dtth=0,i_dtthdich=0;
			if (txtTutk.Text.Trim()!="") i_idtutk=Convert.ToInt32(a.getrowbyid(dttk,"stk='"+txtTutk.Text.Trim()+"'")["id"].ToString().Trim());
			if (txtSangtk.Text.Trim()!="") i_idsangtk=Convert.ToInt32( a.getrowbyid(dttk,"stk='"+txtSangtk.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpnguon.Text.Trim()!="") i_kmcpnguon=Convert.ToInt32( a.getrowbyid(dtkhoanmuc1,"ma='"+txtKmcpnguon.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpnguon2.Text.Trim()!="") i_kmcpnguon2=Convert.ToInt32( a.getrowbyid(dtkhoanmuc2,"ma='"+txtKmcpnguon2.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpnguon3.Text.Trim()!="") i_kmcpnguon3=Convert.ToInt32( a.getrowbyid(dtkhoanmuc3,"ma='"+txtKmcpnguon3.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpnguon4.Text.Trim()!="") i_kmcpnguon4=Convert.ToInt32( a.getrowbyid(dtkhoanmuc4,"ma='"+txtKmcpnguon4.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpdich.Text.Trim()!="") i_kmcpdich=Convert.ToInt32( a.getrowbyid(dtkhoanmucdich1,"ma='"+txtKmcpdich.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpdich2.Text.Trim()!="") i_kmcpdich2=Convert.ToInt32( a.getrowbyid(dtkhoanmucdich2,"ma='"+txtKmcpdich2.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpdich3.Text.Trim()!="") i_kmcpdich3=Convert.ToInt32( a.getrowbyid(dtkhoanmucdich3,"ma='"+txtKmcpdich3.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtKmcpdich4.Text.Trim()!="") i_kmcpdich4=Convert.ToInt32( a.getrowbyid(dtkhoanmucdich4,"ma='"+txtKmcpdich4.Text.Trim()+"'")["id"].ToString().Trim());		
			if(txtDtthnguon.Text.Trim()!="") i_dtth=Convert.ToInt32(a.getrowbyid(dtnv,"id='"+txtDtthnguon.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtDtthdich.Text.Trim()!="") i_dtthdich=Convert.ToInt32(a.getrowbyid(dtnv,"id='"+txtDtthdich.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtLKnguon.Text.Trim()!="") i_lkdich=Convert.ToInt32(a.getrowbyid(dtlk,"lk='"+txtLKdich.Text.Trim()+"'")["id"].ToString().Trim());
			if(txtLKdich.Text.Trim()!="") i_lknguon=Convert.ToInt32(a.getrowbyid(dtlk,"lk='"+txtLKnguon.Text.Trim()+"'")["id"].ToString().Trim());
			if((cbono_co.SelectedIndex)==0)
				i_tinhchattk=1;
			else if((cbono_co.SelectedIndex)==1)
				i_tinhchattk=2;
			else i_tinhchattk=0;
			if (!a.upd_ctkc(l_id,stt.Value,s_yy,(chkKetchuyen.Checked)?1:0,txtSobtoan.Text,txtTenbtoan.Text,i_tinhchattk,i_idtutk,i_idsangtk,i_kmcpnguon,txtNhomkmcpn.Text,i_dtth,(chkKmcpn.Checked)?1:0,i_kmcpnguon2,i_kmcpnguon3,i_kmcpnguon4,i_kmcpdich,i_kmcpdich2,i_kmcpdich3,i_kmcpdich4,(chkTuDtthn.Checked)?1:0,i_dtthdich,Convert.ToInt32(cboKysl.SelectedValue.ToString()),i_lknguon,(chkTulkn.Checked)?1:0,i_lkdich,i_userId,DateTime.Now))
			{
				MessageBox.Show("Không cập nhật thông tin "+this.Text.Trim()+" !",a.Msg);
				return;
			}
			load_grid_ketchuyen(cboKysl.SelectedValue.ToString());
			ena_object(false);
		}

		private void txtTutk_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listtutk.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listtutk.Visible)	listtutk.Focus();
				else SendKeys.Send("{Tab}");
			}		
			else if (e.KeyCode==Keys.Escape) listtutk.Hide();
		}

		private void txtTutk_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtTutk)
			{
				Filter_List(listtutk,txtTutk.Text.Trim(),"stk","");
				listtutk.BrowseToDmtk(txtTutk,txtTutk,txtSangtk,txtTutk.Location.X,txtTutk.Location.Y+txtTutk.Height,500,txtTutk.Height,100);
			}
		}

		private void txtTutk_Validated(object sender, System.EventArgs e)
		{
			DataRow r=a.getrowbyid(dttk,"stk='"+txtTutk.Text+"'");
			txtTutk.Text=(r!=null)?r["ttk"].ToString():"";		
			hidelist();
		}

		private void txtSangtk_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listsangtk.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listsangtk.Visible)	listsangtk.Focus();
				else SendKeys.Send("{Tab}");
			}		
			else if (e.KeyCode==Keys.Escape) listsangtk.Hide();
		}

		private void txtSangtk_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtSangtk)
			{
				//Filter_stk(txtSangtk.Text,listtkno);
				Filter_List(listsangtk,txtSangtk.Text.Trim(),"stk","");
				listsangtk.BrowseToDmtk(txtSangtk,txtSangtk,txtLKnguon,txtSangtk.Location.X,txtSangtk.Location.Y+txtSangtk.Height,500,txtSangtk.Height,100);
			}
		}

		private void txtSangtk_Validated(object sender, System.EventArgs e)
		{
			DataRow r=a.getrowbyid(dttk,"stk='"+txtSangtk.Text+"'");
			txtSangtk.Text=(r!=null)?r["ttk"].ToString():"";		
			hidelist();
		}

		private void ref_text()
		{
			try
			{
				l_id=int.Parse(dataGrid1[dataGrid1.CurrentRowIndex,0].ToString() );
				DataRow r =a.getrowbyid(dtkc,"id="+l_id);
				if(r!=null)
				{	
					stt.Value=decimal.Parse(r["stt"].ToString());
					chkKetchuyen.Checked=r["ketchuyen"].ToString().Trim()=="1";
					txtSobtoan.Text=r["sobtoan"].ToString().Trim();
					txtTenbtoan.Text=r["tenbt"].ToString().Trim();
					cbono_co.Text=r["tentc"].ToString().Trim();
					txtTutk.Text=r["tentutk"].ToString().Trim();
					txtSangtk.Text=r["tensangtk"].ToString().Trim();
					txtLKnguon.Text=r["lknguon"].ToString().Trim();
					chkTulkn.Checked=r["tulkn"].ToString().Trim()=="1";
					txtLKdich.Text=r["lkdich"].ToString().Trim();
					txtNhomkmcpn.Text=r["nhomkmcpn"].ToString().Trim();
					txtKmcpnguon.Text=r["kmcpnguon"].ToString().Trim();
					chkKmcpn.Checked=r["kmcpnguon"].ToString().Trim()=="1";
					txtKmcpdich.Text=r["kmcpdich"].ToString().Trim();
					txtDtthnguon.Text=r["dtthnguon"].ToString().Trim();
					chkTuDtthn.Checked=r["tudtthn"].ToString().Trim()=="1";
					txtDtthdich.Text=r["dtthdich"].ToString().Trim();

				}

				//			dssangtk=a.get_data("select stk from "+a.user+".a_dmtk where id="+dataGrid1[i,9].ToString().Trim());
				//			txtSangtk.Text=dssangtk.Tables[0].Rows[0][0].ToString();
				//			txtLKnguon.Text=dataGrid1[i,18].ToString().Trim();
				//			chkTulkn.Checked=dataGrid1[i,19].ToString().Trim()=="1";
				//			txtLKdich.Text=dataGrid1[i,20].ToString().Trim();
				//			txtNhomkmcpn.Text=dataGrid1[i,11].ToString().Trim();
				//			txtKmcpnguon.Text=dataGrid1[i,10].ToString().Trim();
				//			chkKmcpn.Checked=dataGrid1[i,13].ToString().Trim()=="1";
				//			txtKmcpdich.Text=dataGrid1[i,14].ToString().Trim();
				//			txtDtthnguon.Text=dataGrid1[i,12].ToString().Trim();
				//			chkTuDtthn.Checked=dataGrid1[i,15].ToString().Trim()=="1";
				//			txtDtthdich.Text=dataGrid1[i,16].ToString().Trim();
			}
			catch{};

			
		}
		private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
		{
			ref_text();
		}

		private void butHuy_Click(object sender, System.EventArgs e)
		{
			if (dtkc.Rows.Count==1)
			{
				MessageBox.Show("Không cho phép hủy ?",a.Msg);
				return;
			}				
			if (MessageBox.Show("Đồng ý hủy thông tin này !",a.Msg,MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
			{
				a.execute_data("delete from "+a.user+".a_ctkc"+s_yy+" where id="+long.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString()));
				load_grid_ketchuyen(cboKysl.SelectedValue.ToString());
			}
		}
		private void chkAll_CheckedChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==chkAll)				
			foreach(DataRow r in dtkc.Rows) 
			{
				
				r["chon"]=(chkAll.Checked)?true:false;
			}
			string dk="";
			if(chkAll.Checked)
				dk="ketchuyen=1";
			else
				dk="ketchuyen=0";
			a.get_data("update "+a.user+".a_ctkc"+s_yy+" set "+dk+"");
			
		}
		private void cboKysl_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(this.ActiveControl!=cboKysl) return;
			try
			{
				load_grid_ketchuyen(cboKysl.SelectedValue.ToString());				
			}
			catch{};
		}

		private DataSet chungtuketchuyen(string tinhchat, string stk, string idlk, string idkmcp, 
			string iddtth, string  lkdich, string kmcpdich, string dtthdich)
		{
			sql = "select ";
			if(tinhchat.ToString()== "0")sql += "sum(a.sdno" + s_mm+ ") as tienno,sum(a.sdco" + s_mm+ ") as tienco,";
			if(tinhchat.ToString()== "1")sql += "sum(a.sdno" + s_mm + ") as stien, ";
			if(tinhchat.ToString()== "2")sql += "sum(a.sdco" + s_mm + ") as stien, ";
			if(lkdich.ToString().Length != 0 || lkdich.ToString().Length == 0)sql += "a.chuong as chuong,a.lk as lk,a.khoanmuc as kmcp,a.nghiepvu as dtth,a.mtmuc as mtm,a.madt as madt,dt.loaidt as loaidt,a.hoatdong as hoatdong,a.stka as idtk,b.stk as sotk " + " ";
			else sql += "a.chuong as chuong,a.lk as lk,a.khoanmuc as kmcp,a.nghiepvu as dtth,a.stka as idtk,a.mtmuc as mtm,a.madt as madt,a.hoatdong as hostdong,b.stk as sotk " + " ";
			sql += "from "+a.user+".a_sd" + s_yy + " a left join "+a.user+".a_dmtk b on a.stka=b.id " + " ";
			sql+=" inner join "+a.user+".a_dmdt dt on dt.id=a.madt";			
			sql += " where b.stk like '" + stk + "%'" + 
				(idlk.ToString().Length != 0?" and a.lk in (" + idlk + ")" : " ") +
				(idkmcp.ToString().Length != 0?" and a.khoanmuc in (" + idkmcp + ")" : "") +
				(iddtth.ToString().Length != 0?" and a.nghiepvu in (" + iddtth + ")": " ") + "";
			sql += " group by a.chuong,a.lk,a.khoanmuc,a.nghiepvu,a.mtmuc,a.madt,dt.loaidt,a.hoatdong,a.stka,b.stk";
			sql += " order by a.stka";
			try
			{
				ds=new DataSet();
				ds=a.get_data(sql);
				if(ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch{return null;};		
		}
		private void txtLKnguon_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listkmnguon.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listlknguon.Visible)	listlknguon.Focus();
				else SendKeys.Send("{Tab}");
			}		
			else if (e.KeyCode==Keys.Escape) listlknguon.Hide();
		}

		private void txtLKnguon_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtLKnguon)
			{
				Filter_List(listlknguon,txtLKnguon.Text.Trim(),"lk","");
				listlknguon.BrowseToDmtk(txtLKnguon,txtLKnguon,chkTulkn,txtLKnguon.Location.X,txtLKnguon.Location.Y+txtLKnguon.Height,500,txtLKnguon.Height,100);
			}
		}

		private void txtLKnguon_Validated(object sender, System.EventArgs e)
		{
			DataRow r=a.getrowbyid(dtlk,"lk='"+txtLKnguon.Text+"'");
			txtLKnguon.Text=(r!=null)?r["lk"].ToString():"";		
			hidelist();
		}

		private void txtLKdich_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listkmdich.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listlkdich.Visible)	listlkdich.Focus();
				else SendKeys.Send("{Tab}");
			}		
			else if (e.KeyCode==Keys.Escape) listlkdich.Hide();
		}

		private void txtLKdich_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtLKdich)
			{
				Filter_List(listlkdich,txtLKdich.Text.Trim(),"lk","");
				listlkdich.BrowseToDmtk(txtLKdich,txtLKdich,txtNhomkmcpn,txtLKdich.Location.X,txtLKdich.Location.Y+txtLKdich.Height,500,txtLKdich.Height,100);
			}
		}

		private void txtLKdich_Validated(object sender, System.EventArgs e)
		{
			DataRow r=a.getrowbyid(dtlk,"lk='"+txtLKdich.Text+"'");
			txtLKdich.Text=(r!=null)?r["lk"].ToString():"";		
			hidelist();
		}

		private void txtKmcpnguon_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{			
			try
			{
				if (dtkhoanmuc1!=null && b_khoanmuc1)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listkmnguon.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listkmnguon.Visible) 
						{
							listkmnguon.Focus();
							SendKeys.Send("{Down}");
						}
						else SendKeys.Send("{Tab}");
					}
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}
		}

		private void txtKmcpnguon_TextChanged(object sender, System.EventArgs e)
		{
			try
			{
				if (this.ActiveControl==txtKmcpnguon && dtkhoanmuc1!=null && b_khoanmuc1)
				{
					Filter_List(listkmnguon,txtKmcpnguon.Text.Trim(),"ma","ten");
					listkmnguon.BrowseToDmtk(txtKmcpnguon,txtKmcpnguon,chkKmcpn,txtKmcpnguon.Location.X,txtKmcpnguon.Location.Y+txtKmcpnguon.Height,500,txtKmcpnguon.Height,100);
				}
			}
			catch{};
		}

		private void txtKmcpnguon_Validated(object sender, System.EventArgs e)
		{
			txtKmcpnguon.Text="";
			try
			{
				if (txtKmcpnguon.Text!="" && b_khoanmuc1)
				{
					DataRow r=a.getrowbyid(dtkhoanmuc1,"ma='"+txtKmcpnguon.Text+"'");
					txtKmcpnguon.Text=(r!=null)?r["ma"].ToString():"";														
				}
			}
			catch{}
			hidelist();			
		}

		private void txtKmcpdich_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmucdich1!=null && b_khoanmucdich1)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listkmdich.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listkmdich.Visible)	listkmdich.Focus();
						else SendKeys.Send("{Tab}");
					}		
					else if (e.KeyCode==Keys.Escape) listkmdich.Hide();
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}			
		}

		private void txtKmcpdich_TextChanged(object sender, System.EventArgs e)
		{
			try
			{
				if (this.ActiveControl==txtKmcpdich && dtkhoanmucdich1!=null && b_khoanmucdich1)
				{
					Filter_List(listkmdich,txtKmcpdich.Text.Trim(),"ma","ten");
					listkmdich.BrowseToDmtk(txtKmcpdich,txtKmcpdich,txtDtthnguon,txtKmcpdich.Location.X,txtKmcpdich.Location.Y+txtKmcpdich.Height,500,txtKmcpdich.Height,100);
				}
			}
			catch{};

		}

		private void txtKmcpdich_Validated(object sender, System.EventArgs e)
		{
			txtKmcpdich.Text="";
			try
			{
				if (txtKmcpdich.Text!="" && b_khoanmucdich1)
				{
					DataRow r=a.getrowbyid(dtkhoanmucdich1,"ma='"+txtKmcpdich.Text+"'");
					txtKmcpdich.Text=(r!=null)?r["ma"].ToString():"";																
				}
			}
			catch{}
			hidelist();			
		}

		private void txtDtthnguon_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listkmdich.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listkmdich.Visible)	listkmdich.Focus();
				else SendKeys.Send("{Tab}");
			}		
			else if (e.KeyCode==Keys.Escape) listkmdich.Hide();
		}

		private void txtDtthnguon_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtDtthnguon)
			{
				Filter_List(listngvunguon,txtDtthnguon.Text.Trim(),"id","");
				listngvunguon.BrowseToDmtk(txtDtthnguon,txtDtthnguon,chkTuDtthn,txtDtthnguon.Location.X,txtDtthnguon.Location.Y+txtDtthnguon.Height,500,txtDtthnguon.Height,100);
			}
		}

		private void txtDtthnguon_Validated(object sender, System.EventArgs e)
		{
			DataRow r=a.getrowbyid(dtnv,"id='"+txtDtthnguon.Text+"'");
			txtDtthnguon.Text=(r!=null)?r["id"].ToString():"";		
			hidelist();
		}

		private void txtDtthdich_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listngvudich.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listngvudich.Visible)	listngvudich.Focus();
				else SendKeys.Send("{Tab}");
			}		
			else if (e.KeyCode==Keys.Escape) listngvudich.Hide();
		}

		private void txtDtthdich_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtDtthdich)
			{
				Filter_List(listngvudich,txtDtthdich.Text.Trim(),"id","");
				listngvudich.BrowseToDmtk(txtDtthdich,txtDtthdich,cboKysl,txtDtthdich.Location.X,txtDtthdich.Location.Y+txtDtthdich.Height,500,txtDtthdich.Height,100);
			}
		}

		private void txtDtthdich_Validated(object sender, System.EventArgs e)
		{
			DataRow r=a.getrowbyid(dtnv,"id='"+txtDtthdich.Text+"'");
			txtDtthdich.Text=(r!=null)?r["id"].ToString():"";		
			hidelist();
		}

		private void butketchuyen_Click(object sender, System.EventArgs e)
		{	
			foreach(DataRow r in dtkc.Rows) 
			{
				string s_idlk="",s_idlkdich="",s_iddtth="",s_iddtthdich="",s_idkmcp="",s_idkmcpdich="",s_sobtoan="",s_tenbtoan="";
				string s_noco="",s_tutk="",s_sangtk="";
				int i_chuong=0,i_hoatdong=0,i_nghiepvu=0,i_dt=0,i_loaidt=0;
				long l_idct=0,l_idctct=0;
				decimal d_no=0,d_co=0,d_tien=0;
				if(r["ketchuyen"].ToString()=="1")
				{				
					s_noco=r["tinhchat"].ToString().Trim();
					s_tutk=r["tentutk"].ToString().Trim();
					s_sangtk=r["tensangtk"].ToString().Trim();
					s_sobtoan=r["sobtoan"].ToString().Trim();
					s_tenbtoan=r["tenbt"].ToString().Trim();
					if(r["lknguon"].ToString().Trim()!="")s_idlk=a.getrowbyid(dtlk,"lk='"+r["lknguon"].ToString().Trim()+"'")["id"].ToString().Trim();
					if(r["lkdich"].ToString().Trim()!="")s_idlkdich=a.getrowbyid(dtlk,"lk='"+r["lkdich"].ToString().Trim()+"'")["id"].ToString().Trim();
					if(r["dtthnguon"].ToString().Trim()!="")s_iddtth=a.getrowbyid(dtnv,"id='"+r["dtthnguon"].ToString().Trim()+"'")["id"].ToString().Trim();
					if(r["dtthdich"].ToString().Trim()!="")s_iddtthdich=a.getrowbyid(dtnv,"id='"+r["dtthdich"].ToString().Trim()+"'")["id"].ToString().Trim();
					if(r["kmcpnguon"].ToString().Trim()!="")s_idkmcp=a.getrowbyid(dtkhoanmuc1,"ma='"+r["kmcpnguon"].ToString().Trim()+"'")["id"].ToString().Trim();
					if(r["kmcpdich"].ToString().Trim()!="")s_idkmcpdich=a.getrowbyid(dtkhoanmucdich1,"ma='"+r["kmcpdich"].ToString().Trim()+"'")["id"].ToString().Trim();
					DataSet dsct=new DataSet();
					dsct=chungtuketchuyen(s_noco,s_tutk,s_idlk,s_idkmcp,s_iddtth,s_sangtk,s_idkmcpdich,s_iddtthdich);					
					string s_tinhchat="",s_tkno="",s_tkco="";
					s_tinhchat=r["tinhchat"].ToString().Trim();
					string s_ngaythang="";
					#region Lay ngaygs
					switch(cboKysl.SelectedValue.ToString())
					{
						case "1":
							s_ngaythang="31/01/"+s_yy+"";
							break;
						case "2":
							s_ngaythang="28/02/"+s_yy+"";
							break;
						case "3":
							s_ngaythang="31/03/"+s_yy+"";
							break;
						case "4":
							s_ngaythang="30/04/"+s_yy+"";
							break;
						case "5":
							s_ngaythang="31/05/"+s_yy+"";
							break;
						case "6":
							s_ngaythang="30/06/"+s_yy+"";
							break;
						case "7":
							s_ngaythang="31/07/"+s_yy+"";
							break;
						case "8":
							s_ngaythang="31/08/"+s_yy+"";
							break;
						case "9":
							s_ngaythang="30/09/"+s_yy+"";
							break;
						case "10":
							s_ngaythang="31/10/"+s_yy+"";
							break;
						case "11":
							s_ngaythang="30/10/"+s_yy+"";
							break;
						case "12":
							s_ngaythang="31/12/"+s_yy+"";
							break;
					}
					#endregion dong lay ngaygs
					#region duyet dsct
					foreach(DataRow rs in dsct.Tables[0].Rows)
					{	
						i_chuong=int.Parse(rs["chuong"].ToString().Trim());
						i_hoatdong=int.Parse(rs["hoatdong"].ToString().Trim());
						i_dt=int.Parse(rs["madt"].ToString().Trim());
						i_loaidt=int.Parse(rs["loaidt"].ToString().Trim());
						#region switch s_tinhchat
						switch(s_tinhchat)
						{
							case "1":
								s_tkno=r["sangtk"].ToString().Trim();
								s_tkco=r["tutk"].ToString().Trim();								
								d_tien+=Decimal.Parse(rs["stien"].ToString().Trim());
								
								if (d_tien!=0)
								{
									l_idct=a.getIdct();
									l_idctct=a.getIdctct();
									//a.updCtct(s_mmyy,l_idct,l_idctct,2,int.Parse(s_idlk.ToString()),s_tenbtoan,long.Parse(s_tkno),long.Parse(s_tkco), 0,"",int.Parse(i_chuong.ToString()),6,int.Parse(i_hoatdong.ToString()),23,s_sobtoan,s_ngaythang,s_ngaythang,s_tenbtoan,,long.Parse(s_tkco),int.Parse(i_loaidt.ToString()),long.Parse(i_dt.ToString()),d_tien,0,r["kysl"].ToString().Trim().PadLeft(2,'0'),int.Parse(i_nghiepvu.ToString()),0,0,0,"",0,i_userId);
								}
								break;
							case "2":
								s_tkco=r["sangtk"].ToString().Trim();
								s_tkno=r["tutk"].ToString().Trim();
								d_tien+=Decimal.Parse(rs["stien"].ToString().Trim());
							
								if (d_tien!=0)
								{
									l_idct=a.getIdct();
									l_idctct=a.getIdctct();
									a.updCt(s_mmyy,l_idct,0,"",int.Parse(i_chuong.ToString()),6,int.Parse(i_hoatdong.ToString()),23,s_sobtoan,s_ngaythang,s_ngaythang,s_tenbtoan,long.Parse(s_tkno),long.Parse(s_tkco),int.Parse(i_loaidt.ToString()),long.Parse(i_dt.ToString()),d_tien,0,r["kysl"].ToString().Trim().PadLeft(2,'0'),int.Parse(i_nghiepvu.ToString()),0,0,0,"",0,i_userId);
								}
								break;
							case "0":
								d_no=Decimal.Parse(rs["tienno"].ToString().Trim());
								d_co=Decimal.Parse(rs["tienco"].ToString().Trim());									
								if(d_no!=0)
								{
									s_tkno=r["sangtk"].ToString().Trim();
									s_tkco=r["tutk"].ToString().Trim();
									d_tien+=Decimal.Parse(rs["tienno"].ToString().Trim());
								}
								else if(d_co!=0)
								{
									s_tkco=r["sangtk"].ToString().Trim();
									s_tkno=r["tutk"].ToString().Trim();
									d_tien+=Decimal.Parse(rs["tienco"].ToString().Trim());
								}	
								
								if (d_tien!=0)
								{
									l_idct=a.getIdct();
									l_idctct=a.getIdctct();
									a.updCt(s_mmyy,l_idct,0,"",int.Parse(i_chuong.ToString()),6,int.Parse(i_hoatdong.ToString()),23,s_sobtoan,s_ngaythang,s_ngaythang,s_tenbtoan,long.Parse(s_tkno),long.Parse(s_tkco),int.Parse(i_loaidt.ToString()),long.Parse(i_dt.ToString()),d_tien,0,r["kysl"].ToString().Trim().PadLeft(2,'0'),int.Parse(i_nghiepvu.ToString()),0,0,0,"",0,i_userId);
								}
								break;
						}
						#endregion dong switch s_tinhchat
					}
					#endregion duyet dsct
					if (d_tien!=0)
					{
						l_idct=a.getIdct();
						l_idctct=a.getIdctct();
						a.updCt(s_mmyy,l_idct,0,"",int.Parse(i_chuong.ToString()),6,int.Parse(i_hoatdong.ToString()),23,s_sobtoan,s_ngaythang,s_ngaythang,s_tenbtoan,long.Parse(s_tkno),long.Parse(s_tkco),int.Parse(i_loaidt.ToString()),long.Parse(i_dt.ToString()),d_tien,0,r["kysl"].ToString().Trim().PadLeft(2,'0'),int.Parse(i_nghiepvu.ToString()),0,0,0,"",0,i_userId);
					}
				}
			}			
		}

		private void txtKmcpnguon2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmuc2!=null && b_khoanmuc2)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listKmcpnguon2.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listKmcpnguon2.Visible) 
						{
							listKmcpnguon2.Focus();
							SendKeys.Send("{Down}");
						}
						else SendKeys.Send("{Tab}");
					}
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}
		}

		private void txtKmcpnguon2_TextChanged(object sender, System.EventArgs e)
		{
			try
			{
				if (this.ActiveControl==txtKmcpnguon2 && dtkhoanmuc2!=null && b_khoanmuc2)
				{
					Filter_List(listKmcpnguon2,txtKmcpnguon2.Text.Trim(),"ma","ten");
					listKmcpnguon2.BrowseToDmtk(txtKmcpnguon2,txtKmcpnguon2,chkkmcpnguon2,txtKmcpnguon2.Location.X,txtKmcpnguon2.Location.Y+txtKmcpnguon2.Height,500,txtKmcpnguon2.Height,100);
				}
			}
			catch{};
		}

		private void txtKmcpnguon2_Validated(object sender, System.EventArgs e)
		{
			txtKmcpnguon2.Text="";
			try
			{
				if (txtKmcpnguon2.Text!="" && b_khoanmuc2)
				{
					DataRow r=a.getrowbyid(dtkhoanmuc2,"ma='"+txtKmcpnguon2.Text+"'");
					txtKmcpnguon2.Text=(r!=null)?r["ma"].ToString():"";															
				}
			}
			catch{}
			hidelist();	
		}

		private void txtKmcpdich2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmucdich2!=null && b_khoanmucdich2)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listkmcpdich2.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listkmcpdich2.Visible)	listkmcpdich2.Focus();
						else SendKeys.Send("{Tab}");
					}		
					else if (e.KeyCode==Keys.Escape) listkmcpdich2.Hide();
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}	
		}

		private void txtKmcpdich2_TextChanged(object sender, System.EventArgs e)
		{
			try
			{
				if (this.ActiveControl==txtKmcpdich2 && dtkhoanmucdich2!=null && b_khoanmucdich2)
				{
					Filter_List(listkmcpdich2,txtKmcpdich2.Text.Trim(),"ma","ten");
					listkmcpdich2.BrowseToDmtk(txtKmcpdich2,txtKmcpdich2,txtKmcpnguon3,txtKmcpdich2.Location.X,txtKmcpdich2.Location.Y+txtKmcpdich2.Height,500,txtKmcpdich2.Height,100);
				}
			}
			catch{};			
		}

		private void txtKmcpnguon3_TextChanged(object sender, System.EventArgs e)
		{
			try
			{
				if (this.ActiveControl==txtKmcpnguon3 && dtkhoanmuc3!=null && b_khoanmuc3)
				{
					
					Filter_List(listKmcpnguon3,txtKmcpnguon3.Text.Trim(),"ma","ten");
					listKmcpnguon3.BrowseToDmtk(txtKmcpnguon3,txtKmcpnguon3,chkKmcpnguon3,txtKmcpnguon3.Location.X,txtKmcpnguon3.Location.Y+txtKmcpnguon3.Height,500,txtKmcpnguon3.Height,100);
				}
			}
			catch{};
		}

		private void txtKmcpnguon3_Validated(object sender, System.EventArgs e)
		{
			txtKmcpnguon3.Text="";
			try
			{
				if (txtKmcpnguon3.Text!="" && b_khoanmuc3)
				{
					DataRow r=a.getrowbyid(dtkhoanmuc3,"ma='"+txtKmcpnguon3.Text+"'");
					txtKmcpnguon3.Text=(r!=null)?r["ma"].ToString():"";															
				}
			}
			catch{}
			hidelist();	
		}

		private void txtKmcpdich3_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmucdich3!=null && b_khoanmucdich3)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listKmcpdich3.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listKmcpdich3.Visible)	listKmcpdich3.Focus();
						else SendKeys.Send("{Tab}");
					}		
					else if (e.KeyCode==Keys.Escape) listKmcpdich3.Hide();
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}	
		}

		private void txtKmcpdich3_TextChanged(object sender, System.EventArgs e)
		{
			try
			{
				if (this.ActiveControl==txtKmcpdich3 && dtkhoanmucdich3!=null && b_khoanmucdich3)
				{
					Filter_List(listKmcpdich3,txtKmcpdich3.Text.Trim(),"ma","ten");
					listKmcpdich3.BrowseToDmtk(txtKmcpdich3,txtKmcpdich3,txtKmcpnguon4,txtKmcpdich3.Location.X,txtKmcpdich3.Location.Y+txtKmcpdich3.Height,500,txtKmcpdich3.Height,100);
				}
			}
			catch{};
		}

		private void txtKmcpnguon4_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmuc4!=null && b_khoanmuc4)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listKmcpnguon4.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listKmcpnguon4.Visible) 
						{
							listKmcpnguon4.Focus();
							SendKeys.Send("{Down}");
						}
						else SendKeys.Send("{Tab}");
					}
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}
		}

		private void txtKmcpdich3_Validated(object sender, System.EventArgs e)
		{
			txtKmcpdich3.Text="";
			try
			{
				if (txtKmcpdich3.Text!="" && b_khoanmucdich3)
				{
					DataRow r=a.getrowbyid(dtkhoanmucdich3,"ma='"+txtKmcpdich3.Text+"'");
					txtKmcpdich3.Text=(r!=null)?r["ma"].ToString():"";																
				}
			}
			catch{}
			hidelist();
		}

		private void txtKmcpnguon4_TextChanged(object sender, System.EventArgs e)
		{
			try
			{
				if (this.ActiveControl==txtKmcpnguon4 && dtkhoanmuc4!=null && b_khoanmuc4)
				{
					
					Filter_List(listKmcpnguon4,txtKmcpnguon4.Text.Trim(),"ma","ten");
					listKmcpnguon4.BrowseToDmtk(txtKmcpnguon4,txtKmcpnguon4,chkKmcpnguon4,txtKmcpnguon4.Location.X,txtKmcpnguon4.Location.Y+txtKmcpnguon4.Height,500,txtKmcpnguon4.Height,100);
				}
			}
			catch{};
		}

		private void txtKmcpnguon4_Validated(object sender, System.EventArgs e)
		{
			txtKmcpnguon4.Text="";
			try
			{
				if (txtKmcpnguon4.Text!="" && b_khoanmuc4)
				{
					DataRow r=a.getrowbyid(dtkhoanmuc4,"ma='"+txtKmcpnguon4.Text+"'");
					txtKmcpnguon4.Text=(r!=null)?r["ma"].ToString():"";														
				}
			}
			catch{}
			hidelist();	
		}

		private void txtKmcpdich4_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmucdich4!=null && b_khoanmucdich4)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listKmcpdich4.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listKmcpdich4.Visible)	listKmcpdich4.Focus();
						else SendKeys.Send("{Tab}");
					}		
					else if (e.KeyCode==Keys.Escape) listKmcpdich4.Hide();
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}				
		}

		private void txtKmcpdich4_TextChanged(object sender, System.EventArgs e)
		{
			try
			{
				if (this.ActiveControl==txtKmcpdich4 && dtkhoanmucdich4!=null && b_khoanmucdich4)
				{
					Filter_List(listKmcpdich4,txtKmcpdich4.Text.Trim(),"ma","ten");
					listKmcpdich4.BrowseToDmtk(txtKmcpdich4,txtKmcpdich4,butXem,txtKmcpdich4.Location.X,txtKmcpdich4.Location.Y+txtKmcpdich4.Height,500,txtKmcpdich4.Height,100);
				}
			}
			catch{};
		}

		private void txtKmcpdich2_Validated(object sender, System.EventArgs e)
		{
			txtKmcpdich2.Text="";
			try
			{
				if (txtKmcpdich2.Text!="" && b_khoanmucdich2)
				{
					DataRow r=a.getrowbyid(dtkhoanmucdich2,"ma='"+txtKmcpdich2.Text+"'");
					txtKmcpdich2.Text=(r!=null)?r["ma"].ToString():"";																
				}
			}
			catch{}
			hidelist();	
		}

		private void txtKmcpdich4_Validated(object sender, System.EventArgs e)
		{
			txtKmcpdich4.Text="";
			try
			{
				if (txtKmcpdich4.Text!="" && b_khoanmucdich4)
				{
					DataRow r=a.getrowbyid(dtkhoanmucdich4,"ma='"+txtKmcpdich4.Text+"'");
					txtKmcpdich4.Text=(r!=null)?r["ma"].ToString():"";																	
				}
			}
			catch{}
			hidelist();
		}

		private void txtKmcpnguon_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtTutk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtTutk.Text.Trim()+"'")["loaikm"].ToString().Trim();
				f_LoadKhoanmuc(ref listkmnguon,ref dtkhoanmuc1,s_IDloaikm);
				b_khoanmuc1=true;
			}
			else
			{
				b_khoanmuc1=false;
				txtKmcpnguon.Text="";
				SendKeys.Send("{Tab}");				
			}				
		}

		private void txtKmcpdich_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtSangtk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtSangtk.Text.Trim()+"'")["loaikm"].ToString().Trim();
				f_LoadKhoanmuc(ref listkmdich,ref dtkhoanmucdich1,s_IDloaikm);
				b_khoanmucdich1=true;
			}
			else
			{
				b_khoanmucdich1=false;
				txtKmcpdich.Text="";
				SendKeys.Send("{Tab}");				
			}				
		}

		private void txtKmcpnguon2_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtTutk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtTutk.Text.Trim()+"'")["loaikm2"].ToString().Trim();
				f_LoadKhoanmuc(ref listKmcpnguon2,ref dtkhoanmuc2,s_IDloaikm);
				b_khoanmuc2=true;
			}
			else
			{
				b_khoanmuc2=false;
				txtKmcpnguon2.Text="";
				SendKeys.Send("{Tab}");				
			}				
		}

		private void txtKmcpnguon3_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtTutk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtTutk.Text.Trim()+"'")["loaikm3"].ToString().Trim();
				f_LoadKhoanmuc(ref listKmcpnguon3,ref dtkhoanmuc3,s_IDloaikm);
				b_khoanmuc3=true;
			}
			else
			{
				b_khoanmuc3=false;
				txtKmcpnguon3.Text="";
				SendKeys.Send("{Tab}");				
			}				
		}

		private void txtKmcpnguon4_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtTutk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtTutk.Text.Trim()+"'")["loaikm4"].ToString().Trim();
				f_LoadKhoanmuc(ref listKmcpnguon4,ref dtkhoanmuc4,s_IDloaikm);
				b_khoanmuc4=true;
			}
			else
			{
				b_khoanmuc4=false;
				txtKmcpnguon4.Text="";
				SendKeys.Send("{Tab}");				
			}				
		}

		private void txtKmcpdich2_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtSangtk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtSangtk.Text.Trim()+"'")["loaikm2"].ToString().Trim();
				f_LoadKhoanmuc(ref listkmcpdich2,ref dtkhoanmucdich2,s_IDloaikm);
				b_khoanmucdich2=true;
			}
			else
			{
				b_khoanmucdich2=false;
				txtKmcpdich2.Text="";
				SendKeys.Send("{Tab}");				
			}			
		}

		private void txtKmcpdich3_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtSangtk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtSangtk.Text.Trim()+"'")["loaikm3"].ToString().Trim();
				f_LoadKhoanmuc(ref listKmcpdich3,ref dtkhoanmucdich3,s_IDloaikm);
				b_khoanmucdich3=true;
			}
			else
			{
				b_khoanmucdich3=false;
				txtKmcpdich3.Text="";
				SendKeys.Send("{Tab}");				
			}			
		}

		private void txtKmcpdich4_Enter(object sender, System.EventArgs e)
		{
			string s_IDloaikm="";				
			if (txtSangtk.Text!="")
			{
				s_IDloaikm=a.getrowbyid(dttk,"stk='"+txtSangtk.Text.Trim()+"'")["loaikm4"].ToString().Trim();
				f_LoadKhoanmuc(ref listKmcpdich4,ref dtkhoanmucdich4,s_IDloaikm);
				b_khoanmucdich4=true;
			}
			else
			{
				b_khoanmucdich4=false;
				txtKmcpdich4.Text="";
				SendKeys.Send("{Tab}");				
			}			
		}

		private void txtKmpnguon3_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try
			{
				if (dtkhoanmuc3!=null && b_khoanmuc3)
				{
					if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listKmcpnguon3.Focus();
					else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
					{
						if (listKmcpnguon3.Visible) 
						{
							listKmcpnguon3.Focus();
							SendKeys.Send("{Down}");
						}
						else SendKeys.Send("{Tab}");
					}
				}
				else SendKeys.Send("{Tab}");
			}
			catch{}
		}
	}
}
